View Single Post
Old Feb 6th, 2007, 3:56 PM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
srand(time(NULL) % getpid() );

And DaWei is correct. You want

int choice= rand()%2;
choice ++;

This gives 1 or 2.
If you really want .0 ... .999999 then
double choice=rand();
double next=rand();
choice=(next > choice) ? choice/next : next/choice;

or use something like drand48();
jim mcnamara is offline   Reply With Quote