True or better Random numbers with Javascript

前端 未结 8 673
花落未央
花落未央 2020-11-28 08:41

I have all kinds of resources that rely on javascript random numbers. However, I\'ve been seeing a lot of problems where random isn\'t so random because of the way I\'m gene

相关标签:
8条回答
  • 2020-11-28 09:20

    I made a JavaScript library that uses cosine and sine functions to generate random numbers using Date.now() and new Date().getTime(). For each random number, I test to see if the number has been used. If it has, I repeat the process until I get a new number. If I get a new number, I add the number to the used list and then return the value. In the same library, I also added a randomness tester which loops through a random number generator and looks for patterns. It's nice this way since it loads numbers quickly (I timed it with console.time) without unnecessarily contacting other pages.

    You can find the library here: punbb.atspace.cc/scripts/libraries/random.js

    0 讨论(0)
  • 2020-11-28 09:32

    Even better, you can use quantum cryptography to generate randomness that is very hard to predict. You can use the ANU Quantum Random Numbers API for some randomness that is coercible into a number similarly output by Math.random.

    0 讨论(0)
提交回复
热议问题