Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created November 13, 2012 12:49
Show Gist options
  • Save jonelf/4065600 to your computer and use it in GitHub Desktop.
Save jonelf/4065600 to your computer and use it in GitHub Desktop.
Use Fisher-Yates instead
var results = [];
for (var i = 0; i < 60000; i++) {
var arr = ['A', 'B', 'C'];
arr.sort( function() { return 0.5 - Math.random() } );
results.push(arr);
};
var dict = {};
for (var i = results.length - 1; i >= 0; i--) {
var prop = results[i].join('');
if (dict.hasOwnProperty(prop))
dict[prop]++;
else
dict[prop]=1;
}
for (var key in dict) {
if (dict.hasOwnProperty(key)) {
console.log(key+":"+dict[key]);
}
}
@jonelf
Copy link
Author

jonelf commented Nov 13, 2012

Example result:
ABC:14873
BCA:7451
CAB:7457
CBA:7515
BAC:15119
ACB:7585

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment