[ back to toc ]

Random Number Generator

Date: 2002/04/03 10:04

Q:
In just regular C language, if I wanted to use the random function to get
random numbers from 1 to 10, how would I format the argument to accomplish
this. Thanks
A:
The function random(viod) does not take any argument. The return value of
the function is between 0 and RAND_MAX defined in stdlib.h

Thus you need the expression:

(int)(((double)random())/((double)RAND_MAX)*10.0+0.5)

Regards,
Peter

[ back to toc ]