How do I generate random numbers in Visual C 6.0 in Windows? I tried rand() and random() but they return very large numbers. How would I, for example, generate a random number between 0 and 10?

Thanks

Printable View

- 05-12-2007MavixRandom numbers
How do I generate random numbers in Visual C 6.0 in Windows? I tried rand() and random() but they return very large numbers. How would I, for example, generate a random number between 0 and 10?

Thanks - 05-12-2007ulillillia
Use the modulo function %:

Code:`SomeVariable = srand(something) % 11; // from 0 to 11-1`

- 05-12-2007TactX
For more sophisticated random numbers, you should have a look at preludes article on using rand().

- 05-13-2007Mavix
Thanks!