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
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
High elevation is the best elevation. The higher, the better the view!
My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express
For more sophisticated random numbers, you should have a look at preludes article on using rand().
Thanks!