Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!decvax!mcnc!uvaarpa!umd5!purdue!i.cc.purdue.edu!k.cc.purdue.edu!l.cc.purdue.edu!cik From: cik@l.cc.purdue.edu (Herman Rubin) Newsgroups: comp.lang.c Subject: Re: Random Numbers ... Message-ID: <690@l.cc.purdue.edu> Date: 28 Feb 88 12:58:05 GMT References: <11972@brl-adm.ARPA> <7097@sol.ARPA> <3472@bobkat.UUCP> <7364@brl-smoke.ARPA> Organization: Purdue University Statistics Department Lines: 45 Summary: All pseudo-random procedures are either very expensive or bad (This doesn't belong in comp.lang.c, but too much has already been posted). I would never use a pseudo-random procedure for any job of any importance. However, let me make some suggestions about good, cheap procedures. First, do not make a subroutine call for each random number wanted. Use a buffer! Second, get some physical random bits. And make sure that all bits are random. Third, probably you should want your initial random numbers to be words of random bits. Keep away from floating point or positive random numbers. A fairly good combination of physical and pseudo-random numbers is to have a pseudo-random procedure which uses a long word-shift-register algorithm such as x[i] = x[i-460] XOR x[i-607]; One could replace XOR by + if addition is full-word two's complement. Then one should make the used random variables y[i] = x[i] XOR z[i], where the z's are physical random numbers. For a large job, the z's have to be recycled. The length of the physical random number file should not be too close to a rational number with small numerator and denominator times a power of 2. Even using the pseudo-random numbers alone with a 607-word physical random seed is likely to be much better than anyting else posted here. A major reason for using physical random numbers is that a pseudo-random scheme is likely to have unknown regularities, which the physical random numbers are unlikely to match; a good reason to include the pseudo-random numbers is to guarantee uniformity; one cannot trust the physical random numbers that much. With a good seed, the procedures suggested by Shamir and by Blum and Miccaeli might even be better, but they are very expensive. -- Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907 Phone: (317)494-6054 hrubin@l.cc.purdue.edu (ARPA or UUCP) or hrubin@purccvm.bitnet