使数字更有可能由随机产生 [英] Make a number more probable to result from random
本文介绍了使数字更有可能由随机产生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用x = numpy.random.rand(1)
生成一个介于0和1之间的随机数.如何使x > .5
的概率是x < .5
的2倍?
I'm using x = numpy.random.rand(1)
to generate a random number between 0 and 1. How do I make it so that x > .5
is 2 times more probable than x < .5
?
推荐答案
那是一个合适的名字!
只需对输入进行一点操作即可.首先将x
设置为从0
到1.5
的范围.
Just do a little manipulation of the inputs. First set x
to be in the range from 0
to 1.5
.
x = numpy.random.uniform(1.5)
x
的2/3
机率大于0.5
,而1/3
机率较小.然后,如果x
大于1.0
,请从中减去.5
x
has a 2/3
chance of being greater than 0.5
and 1/3
chance being smaller. Then if x
is greater than 1.0
, subtract .5
from it
if x >= 1.0:
x = x - 0.5
这篇关于使数字更有可能由随机产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文