Generate a random binary number with a variable proportion of '1' bits

前端 未结 7 1782
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 16:55

I need a function to generate random integers. (assume Java long type for now, but this will be extended to BigInteger or BitSet later

相关标签:
7条回答
  • 2020-12-10 17:40

    Use a random generator that generates a uniform float number r between 0 and 1. If r>p then set the bit to 0, otherwise set it to 1

    0 讨论(0)
提交回复
热议问题