kripod / pcg.js

A functional implementation of the PCG family random number generators, written in JavaScript.
MIT License
1 stars 1 forks source link

Repeat values #1

Open tqwhite opened 7 years ago

tqwhite commented 7 years ago

I am stupid about cryptography so please be kind if this is a stupid point.

Reading about the supposed shortcomings of Math.random(), I looked around and found that PCG is said to be good. Since I'm a Javascript guy, that lead me to you and your implementation.

Just looking to see how it works and what it looks like, I made a loop that generated endless random numbers and checked for duplicates. This library produces a duplicate value after 90-100,000 values, once after only 45k iterations.

Of course, random is random and a sequence of coin tosses produces a run of heads sometimes. A duplicate number isn't against the rules. But, it seems like a bad thing to happen so soon, especially since my main use for generator is generating UUIDs (not that I'm generating even 45k of them anytime soon).

So, I did the same thing with Math.random() and, it's been running for a half hour and no duplicate values.

Do I misunderstand something about random numbers? Is this a flaw?

In any case, thanks for the code.

Best Regards, tqii

kripod commented 7 years ago

Could you paste the two different code snippets for random number generation using Math.random and pcg? It would help analyzing the issue. Thank you!

tqwhite commented 7 years ago

Happy to hear from you. Attached is a file that runs either of them. It's simple so don't make fun of me. I'll be interested to know what you learn. pcgTest.js.txt