Whether or not "true" random actually exists is somewhat of a philosophical question. I'd say it doesn't exist, but we've gotta try, right? I have a library which is performing alright, but the #1 critique I get is that it would be much cooler if it was a "true" random library, so I've been considering approaches for a while. I was thinking about how there is noise in the circuitry of our computers, and I thought that if I could measure it, I might be able to exploit that to get a random number based not off of a seeded mathematical calculation, but instead off of a real-world micro-observation. So my question is- is this a sound true random function? If not, please explain how it is vulnerable or biased. Thanks.
To be clear, I don't want compliments, insults, or philosophical debates. I want answers that will poke holes in this and give me specific ways it can be exploited. I'm asking specifically if there is a way to exploit this.
function random(){
var randomBoolean = () => {
var p1 = performance.now(), p1 = performance.now() - p1;
var p2 = performance.now(), p2 = performance.now() - p2;
return p1 == p2 ? randomBoolean() : p1 > p2;
},
randomDigit = () => {
var binary = "";
for(var i = 0; i < 4; i++) binary += +randomBoolean();
return parseInt(binary, 2) > 9 ? randomDigit() : parseInt(binary, 2);
},
random = ".";
for(var i = 0; i < 30; i++) random += randomDigit();
return Number(random);
}
console.log(random());
Aucun commentaire:
Enregistrer un commentaire