开发者

Select an action with probability p [closed]

Closed. This question is off-topic. It is not currently ac开发者_运维百科cepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

What does it mean to say "do this with probability p"? Does it mean that if p > 0.5, we will do "this"?

How would you write the code or algorithm for doing something with the probability p?

Thank you,


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜