Posted By

Zielak on 08/13/12


Tagged

random


Versions (?)

Test randomness in JavaScript


 / Published in: JavaScript
 

This function tests how random will the Math.random() function be. You can test it with rnd(1000000) a couple of times to get results.

  1. function rnd(j){
  2. arr = [0,0]
  3. for(i=0;i<=j;i++){
  4. r = Math.round(Math.random())
  5. arr[r] = arr[r]+1
  6. }
  7. a = arr[0] / arr[1] * 100
  8. return a
  9. }

Report this snippet  

You need to login to post a comment.