davidbau / seedrandom

seeded random number generator for Javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about seeds and collisions

bryc opened this issue · comments

commented

I am wondering how many unique sequences are possible, and the likelihood of collisions given many different seeds.

For instance, seeding a PRNG with all possible 128-bit numbers. Will that yield 2^128 unique number sequences? Or would there be collisions such that two different seeds would produce the same sequence of numbers? Is it related to the 'period' at all? quick has a period of ~2^1600, for example.

The reason why I am asking: I'm thinking of using seedrandom in a pattern generator, and seeding it with a hash (64-bit or 128-bit). The patterns generated would be highly variable, but if the initial seed is a limiting factor, it could greatly reduce the number of possible patterns. I'm hoping that there would be as many outcomes as the hash size I've provided as a seed (2^64 or 2^128).

In another way of putting it, do PRNGs only use x bits of the provided seed? Like if I provide a 128-bit hash string it would only utilize a portion of it. Like an AND mask (e.g. only using 16-bits of 32-bit input: 0xFFFFFFFF & 0xFFFF).

Hope that makes sense.

Most of the algorithms in this library try to use as many seed bits as you provide. However, the algorithms are not designed for cryptographic security and there are probably plenty of collisions that could be predicted by a determined attacker. This is probably not important for a non-security-sensitive application.

For a flavor of what a determined attacker might do, read a paper on key scheduling attacks, e.g.,:

https://www.schneier.com/academic/paperfiles/paper-key-schedule.pdf