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
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
Use the modulo function %:
Code:SomeVariable = srand(something) % 11; // from 0 to 11-1
For more sophisticated random numbers, you should have a look at preludes article on using rand().
Thanks!