Mail Archives: djgpp/1997/06/05/07:38:07
Here is a bit of code from C for Dummies. The book is terrible in
most parts, but this is a nice llittle thing it did. It demonstrates
how to go about generating random numbers using the computers time.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rnd(int range);
int seedrnd(void);
void main(void)
{
int x;
seedrnd();
for (x=o;x<100;x++)
printf("%i\t",rnd(10));
}
int rnd(int range)
{
int r;
r=rand()%range;
return(r);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
On Wed, 04 Jun 1997 14:14:47 -0400, "A. Sinan Unur" <asu1 AT cornell DOT edu>
wrote:
>Alan Wilson wrote:
>
>> It sounds like to me that DJGPP doesnt have a truly random generator > then.
>> "Informal" random numbers are nice but it would be better if we could
>> generate truly random numbers where the frequency of all numbers were > the same...
>
>i guess ignorance is indeed bliss.
>
>this has nothing to do with DJGPP. as has been pointed out very clearly
>in previous responses to you, all computer generated random numbers are
>pseudo-random. (by the way, the only random distribution is _not_ the
>unifrom distribution.)
>
> -- Sinan
- Raw text -