标签:
If given a function that generates a random number from 1 to 5, how do you use this function to generate a random number from 1 to 7 with the same probability? (ie. function a has probability 1/5 per number, function b would have probability 1/7).
int sum = 0;
int times = 5;
while(times>0){
times--;
sum += rand(5);
}
// 5 ~ 25 = 3 *7
return (sum - 2) / 3;
zenefits oa - random(5) to generate a random(7)
标签:
原文地址:http://www.cnblogs.com/marc-leetcode/p/5175013.html