def do (action, probability):
if rand() <= probability:
action
No, it's more or less: choose a random number between 0 and 1 then, if that's is less than or equal to p, do something.
For example, say p is equal to 0.75 (do something with a probability of 75%). When selecting random numbers in the range 0 through 1, about 75% of them will be 0.75 or less.
In terms of programming, you could code this up as (pseudo-code, obviously):
def do (action, probability):
if rand() <= probability:
action
发布评论
评论(1)
不,或多或少:选择一个 0 到 1 之间的随机数,然后,如果该数小于或等于
p
,则执行某些操作。例如,假设
p
等于 0.75(以 75% 的概率做某事)。当选择 0 到 1 范围内的随机数时,大约 75% 的数字将为 0.75 或更小。在编程方面,您可以将其编码为(显然是伪代码):
No, it's more or less: choose a random number between 0 and 1 then, if that's is less than or equal to
p
, do something.For example, say
p
is equal to 0.75 (do something with a probability of 75%). When selecting random numbers in the range 0 through 1, about 75% of them will be 0.75 or less.In terms of programming, you could code this up as (pseudo-code, obviously):