随机数,但有偏见

Elg*_*oog 3 php random

我如何创建一个偏差在数字范围内的随机数生成器?说我有这个:

$rnum = rand(0,200);
Run Code Online (Sandbox Code Playgroud)

所以$rnum == 3,下次$rnum == 106$rnum == 10等等...

但我宁愿偏差范围为80-120,因此更有可能在偏差范围内选择一个数字而不是它.

$rnum == 86下回$rnum == 112$rnum == 93但仍然可以$rnum == 24等等...

我以为我可以做到这一点:

if($rnum < $middle_of_bias){
    $rnum++;
}else{
    $rnum--;
}
Run Code Online (Sandbox Code Playgroud)

但是没有真正起作用,因为你可以看到,$rnum == 1在应用偏见后,它只会使它2不能使这种方法非常成功.

谢谢你的帮助.

编辑:每个人的答案都很棒.我真的很喜欢gnur的一个和Phil H我已经对rmflow的一个进行了修改,它正在按照我想要的方式工作. 感谢每一位帮助过的人!

if (rand(0, 10) > 2)
{
    $rnum = rand($low, $high);
}else{
    $rnum = rand(0, $max);
}
Run Code Online (Sandbox Code Playgroud)

rmf*_*low 12

if (rand(0, 10) > 7)
{
    $rnum = rand(80, 120);
}
else
{
    $rnum = rand(0, 200);
}
Run Code Online (Sandbox Code Playgroud)