Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!edcastle!aiai!ken From: ken@aiai.ed.ac.uk (Ken Johnson) Newsgroups: comp.lang.c Subject: Random long-number generator Summary: shift one left 16 bits, add another one. Keywords: random maxint Message-ID: <1486@skye.ed.ac.uk> Date: 21 Dec 89 16:18:54 GMT References: <83943@linus.UUCP> Reply-To: ken@aiai.UUCP (Ken Johnson) Followup-To: comp.lang.c Organization: AIAI, University of Edinburgh, Scotland Lines: 21 In article <83943@linus.UUCP> rtidd@mwsun.mitre.org writes: # 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). Does anyone have any ideas or any code that # generates random numbers, or anyplace that I can check to find such # code? Suppose you have two random numbers, int r1 and int r2, each chosen so as to lie randomly between 0x0000 and 0xFFFF. Then long r; r = ((long) r1 << 16) | ((long) r2) & 0x0000FFFFL); -- Ken -- Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 212 `I have read your article, Mr Johnson, and I am no wiser now than when I started'. -- `Possibly not, sir, but far better informed.'