Understanding “randomness”

前端 未结 28 2052
轻奢々
轻奢々 2020-11-22 15:28

I can\'t get my head around this, which is more random?

rand()

OR:

rand() * rand()

I´m f

28条回答
  •  名媛妹妹
    2020-11-22 16:01

    Some things about "randomness" are counter-intuitive.

    Assuming flat distribution of rand(), the following will get you non-flat distributions:

    • high bias: sqrt(rand(range^2))
    • bias peaking in the middle: (rand(range) + rand(range))/2
    • low:bias: range - sqrt(rand(range^2))

    There are lots of other ways to create specific bias curves. I did a quick test of rand() * rand() and it gets you a very non-linear distribution.

提交回复
热议问题