Package it.unimi.dsi.test
Class XorShift
java.lang.Object
it.unimi.dsi.test.XorShift
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe number of bits of state of the generator.static final BigInteger[]An array of cofactors.static final BigInteger[]Factors of the Fermat “primes” up to the eleventh (22048 + 1).static long[][]64x64 bit matrices of the form I + La.static final intThe actual number of valid entries incofactor.static long[][]64x64 bit matrices of the form I + Ra.static final BigIntegerThe period of the generator (2BITS− 1). -
Method Summary
Modifier and TypeMethodDescriptionstatic long[][]identity()Returns the identity matrix in compact representation.static booleanisFull(long[][] m) Checks whether a specified matrix in compact representation has full period.static booleanisIdentity(long[][] m) Checks whether a specified matrix in compact representation is the identity.static voidstatic long[][]makeABCMatrix(int a, int b, int c, int bits) Creates a matrix in compact form representing a xorshift generator as suggested by Marsaglia in “Xorshift RNGs”, Journal of Statistical Software, 8:1−6, 2003.static long[][]mPow(long[][][] q, BigInteger e) Computes the power of a matrix to a given exponent, given the quadratures of the matrix.static long[][]multiply(long[][] x, long[][] y) Multiplies two matrices in compact representation.static long[]multiply(long[] x, long[] y) Multiplies two 64x64 bit matrices represented as arrays of longs.static long[][]newMatrix(int bits) Creates a bit matrix in compact representation: only the first and last 64 rows, and only the first 64 columns of the remaining rows are actually represented.static long[][][]quad(long[][] x) Computes the quadratures of a matrix in compact represention.static longword(long[][] matrix, int r, int cw, int bits) Returns a specified word from a matrix in compact representation.
-
Field Details
-
BITS
public static final int BITSThe number of bits of state of the generator.- See Also:
-
twoToBitsMinus1
The period of the generator (2BITS− 1). -
factor
Factors of the Fermat “primes” up to the eleventh (22048 + 1). -
cofactor
An array of cofactors. Entry 0 ≤i<numCofactorscontainstwoToBitsMinus1divided byfactor[i]. Note that some entries can benullifBITSis less then 4096. -
numCofactors
public static final int numCofactorsThe actual number of valid entries incofactor. -
right
public static long[][] right64x64 bit matrices of the form I + Ra. -
left
public static long[][] left64x64 bit matrices of the form I + La.
-
-
Method Details
-
newMatrix
public static long[][] newMatrix(int bits) Creates a bit matrix in compact representation: only the first and last 64 rows, and only the first 64 columns of the remaining rows are actually represented. The remaining entries are returned byword(long[][], int, int, int)by extending the explicit values in a Toeplitz-like fashion. Each row is represented by an array of longs, each representing 64 bits. Bit in columnican be retrieved asrow[i / 64] & 1L << i.- Parameters:
bits- the number of bits in a row.- Returns:
- a new matrix as described above.
-
word
public static long word(long[][] matrix, int r, int cw, int bits) Returns a specified word from a matrix in compact representation.- Parameters:
matrix- a matrix in compact form.r- the row, starting from 0.cw- the column index of a word, starting from 0.bits- the number of bits in a row.- Returns:
- the specified word.
- See Also:
-
multiply
public static long[] multiply(long[] x, long[] y) Multiplies two 64x64 bit matrices represented as arrays of longs.- Parameters:
x- a 64x64 bit matrix.y- a 64x64 bit matrix.- Returns:
- the product of
xandy.
-
multiply
public static long[][] multiply(long[][] x, long[][] y) Multiplies two matrices in compact representation.- Parameters:
x- a matrix in compact representation.y- a matrix in compact representation.- Returns:
- the product of
xandyin compact representation. - See Also:
-
quad
public static long[][][] quad(long[][] x) Computes the quadratures of a matrix in compact represention.- Parameters:
x- a matrix in compact representation.- Returns:
- an array of matrices in compact representation; the
i-th entry of the matrix isx2i(0 ≤i≤BITS). - See Also:
-
identity
public static long[][] identity()Returns the identity matrix in compact representation.- Returns:
- a compact representation of the identity.
- See Also:
-
isIdentity
public static boolean isIdentity(long[][] m) Checks whether a specified matrix in compact representation is the identity.- Returns:
- true if
mis the identity matrix. - See Also:
-
mPow
Computes the power of a matrix to a given exponent, given the quadratures of the matrix.- Parameters:
q- the quadratures of some matrix as returned byquad(long[][]).e- an exponent smaller than or equal to 2BITS.- Returns:
- the matrix whose array of quadratures is
qraised to exponente. - See Also:
-
isFull
public static boolean isFull(long[][] m) Checks whether a specified matrix in compact representation has full period.- Parameters:
m- a matrix in compact representation.- Returns:
- true of
mhas full period (i.e., 2BITS− 1). - See Also:
-
makeABCMatrix
public static long[][] makeABCMatrix(int a, int b, int c, int bits) Creates a matrix in compact form representing a xorshift generator as suggested by Marsaglia in “Xorshift RNGs”, Journal of Statistical Software, 8:1−6, 2003.- Parameters:
a- the first shift parameter.b- the second shift parameter.c- the third shift parameter.bits- the number of bits in a row.- Returns:
- a matrix representing a xorshift generator with specified parameters and number of bits.
- See Also:
-
main
-