Abdul Samad Abdul Samad - 8 months ago 54
C++ Question

Random number c++ in some range

Possible Duplicate:

Generate Random numbers uniformly over entire range

I want to generate the random number in c++ with in some range let say i want to have number between 25 and 63.

How can i have that.


Answer Source

You can use the random functionality included within the additions to the standard library (TR1). Or you can use the same old technique that works in plain C:

25 + ( std::rand() % ( 63 - 25 + 1 ) )