Mail Archives: djgpp/1996/08/28/05:21:21
Mark Gilbert wrote:
>
> I can't figure rand() and random() out. They both seem positively un-random
> giving out the same numbers every time.
>
> Does anyone know of a problem with these functions in DJGPP?
> Does anyone know how to get them working?
When you use rand(), you must initialize a 'seed' with srand.
Such a code initialize the seed with current time.
include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
int n;
long seed;
time(&seed);
srand(seed);
n=rand();
printf ("\n A random number : %d ", n);
}
So you get differents values each time differents. If you don't
initialize the seed, you get always the same random values.
Once I forgot to initialize the seed, amd I had always the same values,
may be was it the same problem as you?
--
/* lievre @mr.insa-tlse.fr */
int main(){char _1='_';int _0x01=0x01^0x01;
char *_="C{ic}cj(KO AT RQG!h{z}6$%dz)okwb/ul|k#jy%wdncsvf";
while (_[_0x01]) putchar (_[_0x01]^_1&0xf^_0x01++&0xf);
putchar (0x14>>1);}
- Raw text -