Package io.github.olyutorskii.aletojio
Class BoundRnd
java.lang.Object
io.github.olyutorskii.aletojio.BoundRnd
Bounded random integer value
[0,bound)
generator.
Random source is RndInt32
.
This implementation uses a fast algorithm(Nearly Divisionless) that does not use a division(/) or remainder(%) but bitmask and right-shift.
Modulo bias removal may consume multiple 32-bit random numbers per one output.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
BoundRnd
Constructor for [0,N) bounded random number.N is upper bound(exclusive).
- Parameters:
rnd
- 32bit random number generatorbound
- upper bound(exclusive) must be 2 or more- Throws:
NullPointerException
- argument is nullIllegalArgumentException
- toosmall bound
-
-
Method Details
-
next
public int next()Return next bounded random number.- Returns:
- [0, bound) random number
-