node-phonetic icon indicating copy to clipboard operation
node-phonetic copied to clipboard

When does it start over?

Open alainux opened this issue 9 years ago • 1 comments

Hi there! thanks for this. I have a question. Using a seed, they will eventually repeat. Is there any way to know when this will happen ?

alainux avatar Jul 08 '15 17:07 alainux

Phonetic's seeding system isn't based on an actual language-provided RNG, but rather MD5. It was done in this fashion to ensure that the same algorithm could be re-implemented reliably in other languages, as well as produce the same results no matter what JS engine and version is being run.

The seed is used to generate the first MD5 binary blob, which is digested into an unsigned 32-bit int, and this is used to calculate the first syllable. This process is repeated every time a new syllable is added. If a seed isn't provided, the output of Math.random() is used for the seed -- this is safe because implementations on other JS engines or other languages don't need to choose a random seed in the same way, as long as it's a sufficiently random number.

The MD5 is re-generated every time Phonetic is called, so the number of syllables required in a single name to produce any discernible pattern given any random seed would approach infinity. If your concern is the randomness of the generated seed in the event that a static seed isn't provided, that relies entirely on the Math.random() implementation in V8. Its randomness is not considered cryptographically secure, however the distribution and range of its generated values has proven more than sufficient for most non-crypto applications.

Sorry for the long-winded answer -- let me know if I misunderstood your concern!

Edit: To be clear, because Phonetic reduces the MD5 down to 32 bits, there is a maximum of 4,294,967,295 unique names it can produce as long as the same number of syllables are requested every time and the complexity configuration values aren't changed. This is true regardless of how the seed is used.

TomFrost avatar Jul 08 '15 20:07 TomFrost