Understanding “randomness”

前端 未结 28 2446
轻奢々
轻奢々 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条回答
  •  -上瘾入骨i
    2020-11-22 16:23

    It might help to think of this in more discrete numbers. Consider want to generate random numbers between 1 and 36, so you decide the easiest way is throwing two fair, 6-sided dice. You get this:

         1    2    3    4    5    6
      -----------------------------
    1|   1    2    3    4    5    6
    2|   2    4    6    8   10   12
    3|   3    6    9   12   15   18
    4|   4    8   12   16   20   24   
    5|   5   10   15   20   25   30
    6|   6   12   18   24   30   36
    

    So we have 36 numbers, but not all of them are fairly represented, and some don't occur at all. Numbers near the center diagonal (bottom-left corner to top-right corner) will occur with the highest frequency.

    The same principles which describe the unfair distribution between dice apply equally to floating point numbers between 0.0 and 1.0.

提交回复
热议问题