Xref: news2.mv.net comp.os.msdos.djgpp:7955 From: Lievre Ludovic Newsgroups: comp.os.msdos.djgpp Subject: Re: DJGPP random blues Date: Tue, 27 Aug 1996 21:20:20 +0200 Organization: INSA Toulouse Lines: 42 Message-ID: <32234A74.14A2@mr.insa-tlse.fr> References: <01bb942b$d2fb26c0$0100007f AT hiway DOT co DOT uk DOT hiway DOT co DOT uk> NNTP-Posting-Host: sunny1.rt.e-technik.th-darmstadt.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit CC: mark DOT gilbert AT pop3 DOT hiway DOT co DOT uk To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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 #include #include 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);}