int Rand5()
{
return rand()%5+1;
}
int Rand7()
{
int ret;
while(1)
{
ret = (Rand5()-1)*5 + Rand5(); 产生[1,25]的整数区间
if(ret >= 22) // //将[1,25]整数区间控制于[1,21]
continue;
else
return ret%7+1; // //将[1,21]映射到[1,7]
}
}
https://www.cnblogs.com/zkfopen/p/11187827.html
https://blog.csdn.net/qq_42719751/article/details/104458219
https://www.i3geek.com/archives/832
[1,21]的原因是为了等概率生成1-7的数