True or better Random numbers with Javascript

前端 未结 8 685
花落未央
花落未央 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

提交回复
热议问题