Issue:
I am trying to create RNG random number generator,using javascript, my objective is to have RNG which generate Random number using seed value , which will give almost impossible to predict the pattern of the random number.
The code starts here:
var digits = 10,
seed = 9999199999;
function nextRand() {
var n = (seed * seed).toString();
while (n.length < digits * 2) {
n = "0" + n;
}
var start = Math.floor(digits / 2),
end = start + digits;
seed = parseInt(n.substring(start, end));
return seed;
}
function nextRandFloat() {
return nextRand() / 9999999999;
}
for (var i = 0; i < 20; i++) {
console.log(nextRandFloat());
}
var results = [];
for (var i = 0; i < 100000; i++) {
var rand = nextRand();
if (results[rand]) {
break;
}
results[rand] = true;
}
console.log(i);
I have run this code in many javascript editor but I didn't get any out put can anyone please explain what i did mistake.