Mail Archives: djgpp/1998/11/03/16:48:58
On 2 Nov 1998 13:24:37 GMT root AT zoltar DOT gatchaman DOT fr (Pierre MAZIERE)
writes:
>Hi everybody,
>I got a problem with the Random Number Generator: I use it this way
>
>int i;
>
>srandom(int seed) /* what is the meaning of this 'seed' ?*/
The seed initializes the PRNG. Try
int x;
printf("Enter a seed: ");
scanf("%d",&x);
srandom(x);
or use one of the clock/time functions.
>for( ... )
>{
> i=random();
> printf("%u \n",i);
> ...
>
>};
>
>Then things:
>- Every time I launch the executable, the sequence of so called random
> numbers printed on screen is always the same ( so where is the
>randomized
> stuff ?)
>- How can I manage to have 'i' between 0 and MaxRandomNumber ?
The easiest way would be i = random() % (MaxRandomNumber+1),
but the probability distribution of i will not be uniform on
(0,MaxRandomNumber) unless:
-PRNG is itself uniform on (0,MAXINT)
-MAXINT % (MaxRandomNumber+1) == 0
But the skew will be probably be minimal, unless you're doing
extensive Monte Carlo analysis.
BTW, what is the maximum period of the library random() function?
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]
- Raw text -