com.robertboothby.djenni.lang.package.html Maven / Gradle / Ivy
Show all versions of core Show documentation
com.robertboothby.djenni.lang
This package contains {@link com.robertboothby.djenni.SupplierBuilder} instances for the core java
types in the java.lang package.
There are currently limitations in the implementation because of a logical flaw - Take Long for example. The full range
between {@link java.lang.Long#MIN_VALUE} and {@link java.lang.Long#MAX_VALUE} cannot be represented by a single Long
value this means that when one uses {@link java.util.concurrent.ThreadLocalRandom#nextLong(long)} one cannot get a single
number that is distributed over the range of values. Thus in order to get a random Long value between the minimum and
maximum one needs to perform at least 2 random number generations. The first to determine whether we are dealing with
the positive values or the negative values (0 must not be forgotten...), the second to generate a long within the chosen
partial range.
Probably the best approach is to have two instances of these types of generators that can be built one being the
"fast" one that deals with ranges that can be randomised simply (in the case of long the range is less than
Long.MAX_VALUE) and a "slow" one that deals with the greater ranges and does the appropriate calculation.
These two types can then be automatically be selected between by the appropriate SupplierBuilder.
Of course a good question to ask is how often do we, when generating random data, need Longs and similar types generated
to the full range.