Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!condict From: condict@cs.vu.nl (Michael Condict) Newsgroups: comp.lang.c Subject: Re: Random number generator Keywords: random maxint Message-ID: <4943@condict.cs.vu.nl> Date: 22 Dec 89 15:25:21 GMT References: <83943@linus.UUCP> Reply-To: condict@cs.vu.nl (Michael Condict) Organization: VU Informatica, Amsterdam Lines: 28 In article <83943@linus.UUCP> rtidd@mwsun.mitre.org writes: |Greetings | |I was trying to generate a random number bewteen 0 and maxlongint (i.e. 2^32) |on my machine (80386 with Interactive). The rand() function that I have |returns a psuedo-random number between 0 and MAXINT (which in this case |is 32768). I thought about generating two random numbers and multiplying |them together, but I realized that would produce a bell-curve-shaped |distrubution (the numbers in the middle would be more likely to occur). | |Does anyone have any ideas or any code that generates random numbers, |or anyplace that I can check to find such code? | Generate the two 16-bit numbers and concatenate them: long_random = (short_random_1 << 16) + short_random_2; Or, if you prefer: long_random = short_random_1 * 65536 + short_random_2; If the rand function generates uniformly distributed random shorts, this will obviously produce uniformly distributed random longs. -- Michael Condict condict@cs.vu.nl Vrije University Amsterdam