From: massimin AT triere DOT ens DOT fr (Pascal Massimino) Newsgroups: comp.os.msdos.djgpp Subject: Re: Random numbers Date: 28 Jan 1997 22:38:46 GMT Organization: Ecole Normale Superieure, Paris, France Lines: 19 Sender: massimin AT triere (Pascal Massimino) Message-ID: <5clv5m$n2m@nef.ens.fr> References: <5ck9gf$ft7$1 AT fizban DOT solace DOT mh DOT se> <32EDC403 DOT 6621 AT ix DOT netcom DOT com> NNTP-Posting-Host: triere.ens.fr To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <32EDC403 DOT 6621 AT ix DOT netcom DOT com>, Terence Ramos writes: |> number =3D (rand() % (highNUM-lowNUM)) + lowNUM + 1; My 2 cents: * use some bit masking, if your clipping range is a power of 2 (faster) ( e.g.: rand() & 0xff instead of rand() % 256 ) * do not use the lowest bits of rand(). Too bad random properties. Try printf'ing rand()&0x01 for instance, you'll be surprised. So, better use ( rand()>>4 ) or ( rand()>>7 ), for instance... * drand48() returns a double in [0,1[ => you can scale/convert it to int after. _But_ drand48() is slooow... Skal --------------------------------------------------------- Pascal Massimino. e-mail: Pascal DOT Massimino AT ens DOT fr http://www.eleves.ens.fr:8080/home/massimin/index.html.en Ecole Normale Superieure. 45, rue d'Ulm. 75005 Paris.