search

Home  >  Q&A  >  body text

python function returns value based on probability

You need to get a value, which is obtained from a function. There are two values ​​​​a and b in the function. It is required that the probability of returning a is 65%, and the probability of returning b is 35%. I would like to ask, how to implement it?

伊谢尔伦伊谢尔伦2744 days ago717

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-05-24 11:36:47

    if random(0,1) < 0.65
        return a
    else
        return b

    reply
    0
  • Cancelreply