Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!uakari.primate.wisc.edu!indri!xanth!mcnc!rti!xyzzy!meissner From: meissner@dg-rtp.dg.com (Michael Meissner) Newsgroups: comp.lang.c Subject: Re: random numbers Message-ID: <491@xyzzy.UUCP> Date: 22 Aug 89 12:43:42 GMT References: <876.24EFA953@busker.FIDONET.ORG> <324@cubmol.BIO.COLUMBIA.EDU> Sender: usenet@xyzzy.UUCP Reply-To: meissner@twohot.dg.com (Michael Meissner) Organization: Data General (Languages @ Research Triangle Park, NC.) Lines: 24 In article <324@cubmol.BIO.COLUMBIA.EDU> ping@cubmol.UUCP (Shiping Zhang) writes: | In article <876.24EFA953@busker.FIDONET.ORG> Rik.Stevans@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@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@dg-rtp.DG.COM faster, when would we