Quote:
Originally Posted by rahul_kulkarni
Hi All,
I want to know how to generate the random numbers between range 1 to n on linux platform. Is there a way to genrate the uniform random numbers over a given range? For instance, if I give n=3 and generate 100 random numbers, each number should get generated 33 times i.e. we should get number 1 33times, number 2 33 times and number 3 33 times.
Any help in this regard would be highly appreciated.
Thanks and Regards,
// Rahul
|
for integer numbers and small ranges of numbers:
Put all numbers you need into array with size equal to size of number range. I.e. Then mix array like a deck of cards (you'll need another random number generator for mixing, but it doesn't have to be uniform or whatever). After that each timeyou'll need random number, read element from array. Elements should be read in sequental order. When you reach last element of array, mix array again. This generator will be uniform enough, but it won't be suitable for large ranges of numbers.