您的位置:首页 > 其它

利用rand7() 产生rand10()(腾讯)

2014-04-11 22:02 393 查看
题目1:已知rand7() 可以产生 1~7 的7个数(均匀概率),利用rand7() 产生rand10() 1~10(均匀概率)

int rand10()
{
int temp;
int temp2;
do
{
temp = rand7();
} while (temp > 5);//temp 1到5
do
{
temp2 = rand7();
while (temp2 > 2);//temp2 1到2
return temp + (temp2 - 1) * 5;
}


题目2:给定能随机生成整数1到5的函数,写出能随机生成整数1到7的函数。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐