Random long-number generator
Ken Johnson
ken at aiai.ed.ac.uk
Fri Dec 22 03:18:54 AEST 1989
In article <83943 at linus.UUCP> rtidd at 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 at 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.'
More information about the Comp.lang.c
mailing list