| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | RANDOM NUMBER: SAME! |
-=> Quoting Gautam Lad to **Anybody** <=-
GL> Hi,
GL> I'm trying to generate floating point random numbers under EMX/GCC,
GL> using the random() function from the BSD libraries. I can generate a
GL> random number (1.2 digit), but it's always the same. If I run the
GL> program, for example, the number will be 0.98, and then I close the
GL> program, and try again a few seconds later, but I get the same number.
GL> I've changed srand(), but no luck. Here's how I generate a number:
GL> number = random()/9999999999.0;
GL> This may look absurd, but I don't know of any other way to do it!
Here's how I'm initializing the random generator in a program:
DATETIME DateTime;
DosGetDateTime(&DateTime);
srandom(DateTime.hundredths*DateTime.seconds);
// using seconds may be overkill
...
number=random();
// get a random number
Stephane [TEAM OS/2]
... Brought to you by the letters O and S, and by the number 2
--- Blue Wave/OS2 v2.20
* Origin: Juxtaposition BBS (1:167/133)SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955 SEEN-BY: 712/407 515 517 628 713/888 800/1 @PATH: 167/133 116 90 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.