How is randomness achieved with Math.random in javascript?

后端 未结 5 514
傲寒
傲寒 2020-11-29 11:02

How is randomness achieved with Math.random in javascript? I\'ve made something that picks between around 50 different options randomly. I\'m wondering how comfortable I sho

5条回答
  •  北海茫月
    2020-11-29 11:45

    The exact implementation can of course differ somewhat depending on the browser, but they all use some kind of pseudo random number generator. Although it's not really random, it's certainly good enough for all general purposes.

    You should only be worried about the randomness if you are using it for something that needs exceptionally good randomness, like encryption or simulating a game of chance in play for money, but then you would hardly use Javascript anyway.

提交回复
热议问题