Hello, I'm new to javascript and I'm using the following function to shuffle characters from a string into a password generator I'm trying to develop:
function shuffle(string) {
"use strict";
var parts = string.split('');
for (var i = parts.length; i > 0;) {
var random = parseInt(Math.random() * i);
var temp = parts[--i];
parts[i] = parts[random];
parts[random] = temp;
}
return parts.join('');
}
But as I was informed, using Math.random()
is not very secure for this purpose. I would like to know how I can tailor my role then using window.crypto.getRandomValues()
who told me to be more secure.
Thanks for any help!