True or better Random numbers with Javascript

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

    Assuming you're not just seeing patterns where there aren't any, try a Mersenee Twister (Wikipedia article here). There are various implementations like this one on github.

    Similar SO question:

    Seedable JavaScript random number generator

    If you want something closer to truly random, then consider using the random.org API to get truly random numbers, although I would suggest only using that to seed, not for every number, as you need to abide by their usage limits.

提交回复
热议问题