I am adding a new family of random generators in commons-rng. The
algorithms do not work when the seed state is all zeros [1]. What would
be best solution for an API. Here are some options:
1. Throw an exception.
2. Fall-back to a known default seed that works.
3. Allow it and users beware (this is the current behaviour for an
existing generator in the library with this defect). A generator may be
created that is broken (e.g. always returns zero).
4. Allow exceptions from the constructor (to prevent misuse) but update
the recommended way of creating a generator to never fail. This is a
modification to the commons-rng-simple API method
RandomSource.create(RandomSource.XXX) to ensure that a seed created by
the library is never bad for the chosen algorithm.
Option 1 is easy but may present a problem to the user of the library
who chooses a bad seed (or one is generated badly by chance).
Option 2 ensures that illegal seeds can be used to create good generators.
Option 3 allows creation of bad generators. This is a bug IMO.
Option 4 should allow a user of the recommended API to never get a bad
generator or an exception. But direct use of the core API requires a
user beware approach as exceptions can happen is used incorrectly.
I am favouring option 4.
Feedback is welcome.
Alex
[1] Many of the algorithms in the library can accept a zero seed for the
initial state. This is because they use additions in the algorithm to
propagate to the next state. The new family uses the Xor operator, bit
shifts and multiplications. If the initial state is all zero this just
remains at zero and the generator is broken.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org