I try to make simple and quick pereatable random number generator in range 0 to 1.000.000 In the function params i receive (String) A (The seed string from first side) and B (Seed from second side)
Received number must be repeatable ... I make some function in JS
SHA256 by library CryptJS http://ift.tt/1vHUZzp
function randomWithSeeds(usr,srv)
{
var hash = CryptoJS.SHA256(CryptoJS.SHA256(usr+srv).toString()).toString();
while (1==1)
{
var index = 0
while (index <= (64-4))
{
r = hash.slice(index, index+4);
work = "";
for (i=0; i<=2; i++) {
work +=r[i].charCodeAt(0);
}
if (Number(work) < 16000000)
return (work % 1000000)
index += 4
}
}
return -1
}
Minimal number I receive is 4848, but expected minimal ZERO .... Please help!
may be for Python also?
Aucun commentaire:
Enregistrer un commentaire