Mail Archives: djgpp/1997/01/28/23:36:01
In article <32EDC403 DOT 6621 AT ix DOT netcom DOT com>, Terence Ramos <de-bug AT ix DOT netcom DOT com> 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.
- Raw text -