Package it.unimi.dsi.test
Class XorShift
- java.lang.Object
-
- it.unimi.dsi.test.XorShift
-
public class XorShift extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXorShift.Compute
-
Field Summary
Fields Modifier and Type Field Description static intBITSThe number of bits of state of the generator.static java.math.BigInteger[]cofactorAn array of cofactors.static java.math.BigInteger[]factorFactors of the Fermat “primes” up to the eleventh (22048 + 1).static long[][]left64x64 bit matrices of the form I + La.static intnumCofactorsThe actual number of valid entries incofactor.static long[][]right64x64 bit matrices of the form I + Ra.static java.math.BigIntegertwoToBitsMinus1The period of the generator (2BITS− 1).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 voidmain(java.lang.String[] arg)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.static long[][]mPow(long[][][] q, java.math.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 Detail
-
BITS
public static final int BITS
The number of bits of state of the generator.- See Also:
- Constant Field Values
-
twoToBitsMinus1
public static final java.math.BigInteger twoToBitsMinus1
The period of the generator (2BITS− 1).
-
factor
public static final java.math.BigInteger[] factor
Factors of the Fermat “primes” up to the eleventh (22048 + 1).
-
cofactor
public static final java.math.BigInteger[] 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 numCofactors
The actual number of valid entries incofactor.
-
right
public static long[][] right
64x64 bit matrices of the form I + Ra.
-
left
public static long[][] left
64x64 bit matrices of the form I + La.
-
-
Method Detail
-
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:
newMatrix(int)
-
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:
newMatrix(int)
-
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:
newMatrix(int)
-
identity
public static long[][] identity()
Returns the identity matrix in compact representation.- Returns:
- a compact representation of the identity.
- See Also:
newMatrix(int)
-
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:
newMatrix(int)
-
mPow
public static long[][] mPow(long[][][] q, java.math.BigInteger e)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:
newMatrix(int)
-
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:
newMatrix(int)
-
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:
newMatrix(int)
-
main
public static void main(java.lang.String[] arg)
-
-