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:
parent
92598b13c2
commit
8ef73aeeeb
@ -102,11 +102,20 @@ var words = function(dbot) {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
'~jimble': function(event) {
|
||||
event.reply(event.params[1].split('').sort(function() {
|
||||
return (Math.round(Math.random()) - 0.5);
|
||||
}).join(''));
|
||||
|
||||
'~jimble': function(event) {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user