Scramble string N times in Node.JS
let myStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz\\\"";
function scramble(str, times) {
str = Buffer.from(str, 'utf8');
console.log(str + " >>>----> " + str.length + " chars");
for (let i = 1; i <= times; i++) {
let orig = Math.floor(Math.random() * str.length);
let dest = Math.floor(Math.random() * str.length);
let temp = str[orig];
str[orig] = str[dest];
str[dest] = temp;
}
console.log(str + " >>>----> " + str.length + " chars");
}
scramble(myStr, 223);
Expected output (mileage may vary):
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz\" >>>----> 64 chars
4RjeE6DzBtYGAFTrbymnxIZXNq9c0kV"sUWhPiLKg\avJfSHl72p385uCwOdQM1o >>>----> 64 chars