octgn / OCTGN4

2 stars 1 forks source link

Research js Randomness for Shuffling #1

Open kellyelton opened 8 years ago

kellyelton commented 8 years ago

We need to research and come up with a good method to shuffle in JS with a good random.

There are 3 purposes of this ticket

  1. Develop a way to test algorithms and random sources
  2. Lay out all the different ways we could generate a random seed for use with the randomizer function signature
  3. Figure out which platforms we need to test on and update this ticket.

    1. Develop a way to test algorithms and random sources

We need a method that takes uses the shuffle function below and tests it's randomness.

The trick here is that you should expect that the js engine will be running headless(no actual visuals). The task is actually a 2 part task.

  1. Create the actual test, and have it output data we can look at later
  2. Have a separate script(preferably a jsFiddle that can take the data produced and create a graph or something from it(kind of like this https://jsfiddle.net/kellyelton/8s1jejho/2/)
// array: a js array of numbers in order, the amount is not known at this time
// randomizer: a function that returns a random number. It's defined below
shuffle(array, randomizer){
  var random = array.map(randomizer);
  array.sort(function(a, b) {
    return random[a] - random[b];
  });
}

// returns:  Random decimal between 0 and 1
randomizer()

2. Lay out all the different ways we could generate a random seed for use with the randomizer function signature

When the first part gets done, then we can start posting some overloads of the randomizer function for testing.

3.Figure out which platforms we need to test on and update this ticket.

Once we're done with 1 and 2 we should figure out which js engines we need to test against and update this ticket. We should then update our testing method to make sure it works on all of the engines.

Some links

http://hackaday.com/2015/12/28/v8-javascript-fixes-horrible-random-number-generator/

https://github.com/clipperz/javascript-crypto-library

https://github.com/simbo1905/srp-6a-demo/blob/master/srp/Client/lib/random.js

https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues

http://chancejs.com/

https://github.com/simbo1905/srp-6a-demo/blob/master/srp/Client/lib/random.js

Gravecorp commented 8 years ago

https://gist.github.com/ne-sachirou/852327 another random alternative