Click to See Complete Forum and Search --> : how can i do it??? urgent.


September 17th, 1999, 10:44 AM
Hi guys i just can't write the rand() to return specific number from 0 up to 6.
Can anybody help me out.

Thanks alot.

September 17th, 1999, 10:54 AM
Try this

int random = (int)((double)rand()/(double)RAND_MAX * 6.0);

This should give random numbers from and including 0 up to and
including 6.

September 25th, 1999, 02:31 AM
Why not just:

int randomValue = rand() % 6;

That's better than casting all over the place.