Message-ID: <32240E1F.1D96@pobox.oleane.com> Date: Wed, 28 Aug 1996 11:15:11 +0200 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: Mark Gilbert CC: djgpp AT delorie DOT com Subject: Re: DJGPP random blues References: <01bb942b$d2fb26c0$0100007f AT hiway DOT co DOT uk DOT hiway DOT co DOT uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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? > Are you sure : 1/ that you include the header 2/ that before calling rand(), you *first* call the srand() function, which initialize rand(), if you don't things like this *will* occur. Not that everytime your call srand() with the same parameter, you get the same random serie (a useful feature if you need to use the same random numbers several times. If this does not help, post the piece of code that calls rand() and an example of the results you get... Also, rand() has a bug, (but not the one you describe, at least on my machine...) : it is not *very* random, in the sense that the numbers it outputs "loop over" every about 30 million iterations. This is no big deal if you justwant some "slight" alea, without caring whether this is actually random or not. But if you are doing anything involving *real* randomness, use random() or, better, a specific routines (places to look for this are Numerical Recipes in C, 2nd edition, they have a web page with the book online, look it up..., and Knuth's Art of Computer Programming, part II). Regards, Francois