Decision:
Both the weak_rng and the random function are little helpers, but don't really do much. To be clear, in the next release users may simply:
- replace
random() with thread_rng().gen()
- replace
weak_rng() with XorShiftRng::new() (or a different PRNG)
The first is pure convenience (but also a minor anti-pattern since caching the result of thread_rng can improve performance).
The second has a small advantage: users may specify simply that they want a fast, weak PRNG, and don't mind if the implementation changes. XorShiftRng is reproducible, meaning that library updates won't change its output; weak_rng is not reproducible, meaning the library may replace the internals with better generators in the future.
Note that currently weak_rng() returns XorShiftRng which makes changing the former a breaking change; we should introduce a wrapper around the generator used (i.e. fn weak_rng() -> WeakRng) or drop the function and only use a wrapper type (WeakRng::new()).
Note also that thread_rng() is staying because it is widely used and has additional features.
We already wish to change the weak_rng algorithm and have two candidates (see dhardy#52 and dhardy#60), so it's possible we could have two variants, e.g. FastRng and SmallRng. This issue is not about which algorithm we choose.
- remove the
random() convenience function?
- keep
weak_rng() or rename or only keep wrapper types, or remove completely?
Decision:
random()functionweak_rng()function withSmallRngwrapperSmallRng(but off topic here, thus not a blocker for this issue)Both the
weak_rngand therandomfunction are little helpers, but don't really do much. To be clear, in the next release users may simply:random()withthread_rng().gen()weak_rng()withXorShiftRng::new()(or a different PRNG)The first is pure convenience (but also a minor anti-pattern since caching the result of
thread_rngcan improve performance).The second has a small advantage: users may specify simply that they want a fast, weak PRNG, and don't mind if the implementation changes.
XorShiftRngis reproducible, meaning that library updates won't change its output;weak_rngis not reproducible, meaning the library may replace the internals with better generators in the future.Note that currently
weak_rng()returnsXorShiftRngwhich makes changing the former a breaking change; we should introduce a wrapper around the generator used (i.e.fn weak_rng() -> WeakRng) or drop the function and only use a wrapper type (WeakRng::new()).Note also that
thread_rng()is staying because it is widely used and has additional features.We already wish to change the
weak_rngalgorithm and have two candidates (see dhardy#52 and dhardy#60), so it's possible we could have two variants, e.g.FastRngandSmallRng. This issue is not about which algorithm we choose.random()convenience function?weak_rng()or rename or only keep wrapper types, or remove completely?