TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DARIN CROSSLAND
from: PAUL GREEN
date: 1997-05-14 09:18:00
subject: Re: Throw of dice

Hello Darin,
 In a message dated 07 May 97 you wrote to Bill Bussone:
 DC> Well, the easy way would be to close the routine into a loop that would
 DC> only permit an exit if the random number generated was in hte range of
 DC> 1-6. A DO_WHILE type loop would be an effective way.
That's a way of doing it, but it might take forever to actually generate a
number in the correct range.
 DC> Now as to the "True" random result, your outa luck... All you can do, as
 DC> far as I know, is do some fun and funky math to the system clock. So
 DC> haveing the same time on two systems, and the same exit times from the
 DC> programs, they will reproduce the same number sequence.
That's true, but the time it gets from the system clock is not just a case of
hours and minutes - it takes into account seconds and fractions of seconds, 
o
the probability of getting the exact same time value back is virtually nil.
  If I was writing the program, it would be something like this:
#include 
#include 
#include 
int roll_dice(int max)
{
    srand(time(NULL));
    return (rand() %max)+1;
}
int main()
{
    printf("%d",roll_dice(6));
    return 0;
}
   ___
  /__/      Fido:  2:250/344.0    Internet: pgreen@borghome.demon.co.uk
 /   aul    Sysop of the Borg Homeworld BBS (0113) 2253772 - Borgnet NC
... Make like a shepherd and get the flock out of here.
-=o Paul's Groovy Tagline Generator v1.1, (c) 1996 Paul Green o=-
--- Mail Manager 1.22x/n #1215
---------------
* Origin: The Borg Homeworld BBS! (0113) 2253772 V34 (2:250/344.0)

SOURCE: echomail via exec-pc

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™.