Package squidpony.squidmath
Class FlawedRandomness.BigCounter
java.lang.Object
squidpony.squidmath.FlawedRandomness.BigCounter
- All Implemented Interfaces:
Serializable
,FlawedRandomness
,IFlawed
,RandomnessSource
,StatefulRandomness
- Enclosing interface:
- FlawedRandomness
public static class FlawedRandomness.BigCounter extends Object implements FlawedRandomness, StatefulRandomness
A flawed randomness source that depends almost entirely on its starting state for any random-seeming results in
its output. Simply outputs a number that starts with the initial seed and increases by
0x1111111111111111
each time, or 1229782938247303441
.- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface squidpony.squidmath.FlawedRandomness
FlawedRandomness.AddRotate, FlawedRandomness.BigCounter
-
Field Summary
Fields Modifier and Type Field Description long
state
-
Constructor Summary
Constructors Constructor Description BigCounter()
BigCounter(long state)
-
Method Summary
Modifier and Type Method Description FlawedRandomness.BigCounter
copy()
Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the copy, both will generate the same sequence of random numbers from the point copy() was called.long
getState()
Get the current internal state of the StatefulRandomness as a long.int
next(int bits)
Using this method, any algorithm that might use the built-in Java Random can interface with this randomness source.long
nextLong()
Using this method, any algorithm that needs to efficiently generate more than 32 bits of random data can interface with this randomness source.void
setState(long state)
Set the current internal state of this StatefulRandomness with a long.
-
Field Details
-
Constructor Details
-
BigCounter
public BigCounter() -
BigCounter
-
-
Method Details
-
getState
Description copied from interface:StatefulRandomness
Get the current internal state of the StatefulRandomness as a long.- Specified by:
getState
in interfaceStatefulRandomness
- Returns:
- the current internal state of this object.
-
setState
Description copied from interface:StatefulRandomness
Set the current internal state of this StatefulRandomness with a long.- Specified by:
setState
in interfaceStatefulRandomness
- Parameters:
state
- a 64-bit long. You should avoid passing 0, even though some implementations can handle that.
-
next
Description copied from interface:RandomnessSource
Using this method, any algorithm that might use the built-in Java Random can interface with this randomness source.- Specified by:
next
in interfaceRandomnessSource
- Parameters:
bits
- the number of bits to be returned- Returns:
- the integer containing the appropriate number of bits
-
nextLong
Description copied from interface:RandomnessSource
Using this method, any algorithm that needs to efficiently generate more than 32 bits of random data can interface with this randomness source. Get a random long between Long.MIN_VALUE and Long.MAX_VALUE (both inclusive).- Specified by:
nextLong
in interfaceRandomnessSource
- Returns:
- a random long between Long.MIN_VALUE and Long.MAX_VALUE (both inclusive)
-
copy
Description copied from interface:RandomnessSource
Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the copy, both will generate the same sequence of random numbers from the point copy() was called. This just needs to copy the state so it isn't shared, usually, and produce a new value with the same exact state.- Specified by:
copy
in interfaceRandomnessSource
- Specified by:
copy
in interfaceStatefulRandomness
- Returns:
- a copy of this RandomnessSource
-