Académique Documents
Professionnel Documents
Culture Documents
Write a custom random number generation algo which should be 73% biased to the
higher number. Like if I want a random number between 1 to 10 100times then it should
give number more than 5 73times and less than 5 27times.
Algorithm:
Step 3 : Calculate range of biased numbers by mid_val (excluding mid_val) eg. 73%
above 5 and 27% below 5
min_list := min_list will contain value from range 'a' to mid_val-1
max_list := max_list will contain value from range mid_val+1 to b+1
1. First take the lower limit and upper limit of range from user. Calculate mid value
from these two limits to separate the range into two parts upper range and lower
range.
2. Then create two list say min_list which will contain values from lower limit to mid
value(excluding) and max_list which will contain values from mid value
(excluding) to upper limit.
3. Start the while loop1 until the length of max_list becomes 73. In this loop random
number is generated using Linear congruential generator(LCG) method in which
an equation is used ie [number = (increment + current time * multiplier) % mod]
and then 'number' generated from this equation is put into [value = number /
mod] (which will give output value between 0 and 1). And this value is put into a
formula [lower limit + value * (upper limit - lower limit] to calculate random
number in given desired range. Then add final value to max_list
4. Start the second while loop2 until the length of min list becomes 27. Same
procedure is done as above while loop1 Then add final value to min_list