random numbers

Michael Meissner meissner at dg-rtp.dg.com
Tue Aug 22 22:43:42 AEST 1989


In article <324 at cubmol.BIO.COLUMBIA.EDU> ping at cubmol.UUCP (Shiping Zhang) writes:
| In article <876.24EFA953 at busker.FIDONET.ORG> Rik.Stevans at f226.n105.z1.FIDONET.ORG (Rik Stevans) writes:
| >Does anyone have a good random number generator for 'c'?  i need a 
| >function which will return an integer less than zero (just like rnd 
| >in basic) and be fairly random.  the one i wrote does ok but is very 
| >unweildly as i cast from double back to int to get the numbers i need. 
| >thanks, rik s...
| >--  
| >Rik Stevans - via FidoNet node 1:105/14
| >	    UUCP: ...!{uunet!oresoft, tektronix!reed}!busker!226!Rik.Stevans
| >	    ARPA: Rik.Stevans at f226.n105.z1.FIDONET.ORG
| 
| There are functions that generate random integers in the C standard
| library. Take a look at your manual.

But the requestor wanted a "GOOD" random number generator, and "rand"
which is in the C standard, is typically not all that good.  If your
system is based on Berkeley, look up "random(3)" in the documentation.
If your system is based on System V, look up "lrand48(3)" and friends.
These random number generators are much better.  Typical seed values
in UNIX are based on the time of day, date and/or process ID.
--
Michael Meissner, Data General.
Uucp:		...!mcnc!rti!xyzzy!meissner		If compiles were much
Internet:	meissner at dg-rtp.DG.COM			faster, when would we



More information about the Comp.lang.c mailing list