I want the random number generation to be controllable with a variable. For example, if I say 100, numbers should be generated with maximum randomness, and if I say 50, the numbers should not be ‘as random’. If I say ‘0’, possibly the random numbers should not be random at all – maybe all numbers generated are same.
Any idea what I can use to generate controlled random numbers like these? Any idea if some C++ inbuilt library, or maybe Boost library does this?
It will be good to have a way to regenerate the same sequence of random numbers, so a way to seed the generator would also be good.
The way you describe your requirement seems to suggest that using a normal distribution (aka Gaussian distribution) may be the way to go. It has two parameters: Mean and standard deviation. If you set the standard deviation very low, you get random values that are probably quite close to the mean. If you set it to a large value, you get them distributed more widely.
In C++11 a normal distribution is available from the standard library. If C++11 is not an option for you, the Boost library has it, too.
Here is some example code:
Here is the output:
As you can see, in the first row all numbers are quite close to 5 (i.e., to use your wording, “randomness” is low), while in the second row the numbers are spread much more widely.
(EDIT: Of course, the randomness of these numbers isn’t really affected. It’s just that the standard deviation parameter makes the values more likely to emerge in a smaller (stddev low) or wider (stddev high) range of numbers.)