Generate Random numbers without using any external functions

后端 未结 9 1012
梦如初夏
梦如初夏 2020-12-08 16:26

This was questions asked in one of the interviews that I recently attended.

As far as I know a random number between two numbers can be generated as follows

9条回答
  •  情书的邮戳
    2020-12-08 16:48

    You can get near randomness (actually chaotic and definitely not uniform*) from the logistic map x = 4x(1-x) starting with a "non-rational" x between 0 and 1.

    The "randomness" appears because of the rounding errors at the edge of the accuracy of the floating point representation.

    (*)You can undo the skewing once you know it is there.

提交回复
热议问题