How is randomness achieved with Math.random in javascript?

后端 未结 5 516
傲寒
傲寒 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条回答
  •  Happy的楠姐
    2020-11-29 11:48

    From the specifications:

    random():

    Returns a Number value with positive sign, greater than or equal to 0 but less than 1, chosen randomly or pseudo randomly with approximately uniform distribution over that range, using an implementation-dependent algorithm or strategy. This function takes no arguments.

    So the answer is that it depends on what JavaScript engine you're using.

    I'm not sure if all browsers use the same strategy or what that strategy is unfortunately

    It should be fine for your purposes. Only if you're doing a large amount of numbers would you begin to see a pattern

提交回复
热议问题