mirror of
https://github.com/reality/dbot.git
synced 2025-01-11 20:42:37 +01:00
Produce uniformly-distributed permutation in ~jimble
This commit is contained in:
parent
92598b13c2
commit
8ef73aeeeb
@ -104,9 +104,18 @@ var words = function(dbot) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'~jimble': function(event) {
|
'~jimble': function(event) {
|
||||||
event.reply(event.params[1].split('').sort(function() {
|
var word = event.params[1].split('');
|
||||||
return (Math.round(Math.random()) - 0.5);
|
var used = [];
|
||||||
}).join(''));
|
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) {
|
'~merge': function(event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user