public class SquidID extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<SquidID>
store()
and load(CharSequence)
.
Constructor and Description |
---|
SquidID()
Constructs a new random SquidID.
|
SquidID(int a,
int b,
int c,
int d)
Constructs a fixed SquidID with the given four 32-bit ints, which will be used exactly.
|
SquidID(long low,
long high)
Constructs a fixed SquidID with the given low and high 64-bit longs.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(SquidID o) |
boolean |
equals(java.lang.Object o) |
int |
getA()
Gets the 32 least-significant bits as an int.
|
int |
getB()
Gets the 32 second-to-least-significant bits as an int.
|
int |
getC()
Gets the 32 second-to-most-significant bits as an int.
|
int |
getD()
Gets the 32 most-significant bits as an int.
|
long |
getLeastSignificantBits()
Gets the least-significant bits, also accessible by the field low.
|
long |
getMostSignificantBits()
Gets the most-significant bits, also accessible by the field high.
|
int |
hashCode() |
static void |
load(java.lang.CharSequence data)
Makes the IDs generated after calling this repeatable, with the same IDs generated in order after this is called.
|
static void |
randomize()
Makes the IDs generated after calling this non-repeatable, with a random 128-bit seed.
|
static SquidID |
randomUUID()
Gets a new random SquidID, the same as calling the no-argument constructor.
|
static void |
stabilize()
Makes the IDs generated after calling this repeatable, with the same IDs generated in order after this is called.
|
static java.lang.StringBuilder |
store() |
java.lang.String |
toString() |
public SquidID()
public SquidID(int a, int b, int c, int d)
a
- the least-significant bits of the IDb
- the second-to-least-significant bits of the IDc
- the second-to-most-significant bits of the IDd
- the most-significant bits of the IDpublic SquidID(long low, long high)
low
- the least-significant bits of the IDhigh
- the most-significant bits of the IDpublic static SquidID randomUUID()
public static void stabilize()
XoshiroStarPhi32RNG
this uses make it incredibly unlikely that IDs will repeat even if the game was run
for years without stopping. For the purposes of tests, you may want stable SquidID values to be generated, the
same for every startup of the program, generating the same IDs in order. This will change the seed used
internally to a constant (large) seed the first time it is called, and it should only be called at or near the
start of your program, no more than once. If an ID is requested immediately after calling this method, and then
this method is called again, the next ID to be generated will be identical to the previous one generated (a
collision). There may be reasons you want this during testing, so there isn't any check for multiple calls to
this method. If IDs can persist between runs of the game (i.e. saved in a file), using this is generally a bad
idea, and you should instead use either random IDs or save the state with.
SquidID.load("C13FA9A902A6328F91E10DA5C79E7B1D")
, which are values based on the Plastic Constant (2 to
the 64 divided by the plastic constant, upper 32 bits and then lower 32 bits, then the upper and lower bits of
that number divided again by the plastic constant). Irrational numbers like the plastic constant generally have a
good distribution of bits, which should help delay the point when the generator hits "zeroland" and produces
multiple small numbers for a short while.public static java.lang.StringBuilder store()
public static void load(java.lang.CharSequence data)
XoshiroStarPhi32RNG
this uses make it incredibly unlikely that IDs will repeat even if the game was run
for years without stopping. For the purposes of tests, you may want stable SquidID values to be generated, the
same for every startup of the program, generating the same IDs in order; you may also want this when loading a
saved game. This will change the seed used internally to match a value that should have been produced by
store()
but can be any 32 hex digits, and it should only be called at or near the start of your program,
no more than once per load of a save. If an ID is requested immediately after calling this method, and then this
method is called again with the same data parameter, the next ID to be generated will be identical to the
previous one generated (a collision). There may be reasons you want this during testing, so there isn't any check
for multiple calls to this method. If IDs can persist between runs of the game (i.e. saved in a file), you can be
fine with random IDs in almost all cases, or you can have more certainty by saving the last state of the
generator using store()
when saving and loading that state with this method later.
public static void randomize()
XoshiroStarPhi32RNG
this uses make it incredibly unlikely that IDs will repeat even if the game was run
for years without stopping. However, if you call stabilize(), generate some IDs, call stabilize() again, and
generate some more IDs, the first, second, third, etc. IDs generated after each call will be identical -- hardly
the unique ID you usually want. You can "undo" the effects of stabilize by calling this method, making the seed a
new random value. This does not affect the constructor that takes two longs to produce an exact ID, nor will it
change any existing IDs.public long getLeastSignificantBits()
public long getMostSignificantBits()
public int getA()
public int getB()
public int getC()
public int getD()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.