Right now, the implementation of RNG only allows subclasses to implement two methods, namely:
randomRangeImpl
randomProbabilityImpl
and it then uses these on a concrete, registered instance of a subclass of RNG to handle all tasks requiring randomness.
This is not very good, for example, when it comes to shuffling a container, or picking a random element from a container.
Instead, RNG should have static methods that call default virtual protected Impl methods. The current static implementation will be moved to these Impl methods, and subclasses of RNG can override them with more efficient implementations.
For example, right now we have:
public static auto RNG::randomElement
which uses the concrete RNG subclass implementation's randomRangeImpl to get the element in an inefficient way.
Instead, we should have, in RNG:
public static auto RNG::randomElement that simply calls:
protected virtual auto RNG::randomElementImpl, which contains the code currently in the static method.
Then DefaultRNG will override this with a more efficient implementation.
Right now, the implementation of
RNG
only allows subclasses to implement two methods, namely:randomRangeImpl
randomProbabilityImpl
and it then uses these on a concrete, registered instance of a subclass of
RNG
to handle all tasks requiring randomness.This is not very good, for example, when it comes to shuffling a container, or picking a random element from a container.
Instead,
RNG
should have static methods that call default virtual protectedImpl
methods. The current static implementation will be moved to theseImpl
methods, and subclasses ofRNG
can override them with more efficient implementations.For example, right now we have:
public static auto RNG::randomElement
which uses the concrete
RNG
subclass implementation'srandomRangeImpl
to get the element in an inefficient way.Instead, we should have, in
RNG
:public static auto RNG::randomElement
that simply calls:protected virtual auto RNG::randomElementImpl
, which contains the code currently in the static method.Then
DefaultRNG
will override this with a more efficient implementation.