mardi 28 août 2018

How to get one random element from an array using mersenne twister in javascript?

I inherited a gambling project, where mersenne twister is used as a random nunmber generator.

But I am not sure about the implementation of the same.

The library that is used gives random number [0,1>

Now, for the purpose of the app, it should give back one random number from an array of [0,1,2,...,n>

I was wondering, what is the easiest way to implement this, that is statistically correct. (that it passes bigcrush for example)

I believe that current implementation is very bad

https://gist.github.com/matejthetree/5c510babe767634b6c5189d9e482aca3

It is used to shuffle an array and then take one member from that array, instead of taking random [0,length> and choosing array[random]




Aucun commentaire:

Enregistrer un commentaire