3
0
mirror of https://github.com/reality/dbot.git synced 2025-01-11 12:32:36 +01:00

Produce uniformly-distributed permutation in ~jimble

This commit is contained in:
Michael Jones 2017-01-23 03:11:33 +00:00
parent 92598b13c2
commit 8ef73aeeeb

View File

@ -104,9 +104,18 @@ var words = function(dbot) {
},
'~jimble': function(event) {
event.reply(event.params[1].split('').sort(function() {
return (Math.round(Math.random()) - 0.5);
}).join(''));
var word = event.params[1].split('');
var used = [];
var jimbled = new Array(word.length);
for (var i = 0; i < word.length; i++) {
do {
rnd = Math.floor(Math.random()*word.length);
} while (used.indexOf(rnd) != -1);
jimbled[i] = word[rnd];
used.push(rnd);
}
event.reply(jimbled.join(''));
},
'~merge': function(event) {