Class XorShift

java.lang.Object
it.unimi.dsi.test.XorShift

public class XorShift extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The 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 int
    The actual number of valid entries in cofactor.
    static long[][]
    64x64 bit matrices of the form I + Ra.
    static final BigInteger
    The period of the generator (2BITS − 1).
  • Method Summary

    Modifier and Type
    Method
    Description
    static long[][]
    Returns the identity matrix in compact representation.
    static boolean
    isFull(long[][] m)
    Checks whether a specified matrix in compact representation has full period.
    static boolean
    isIdentity(long[][] m)
    Checks whether a specified matrix in compact representation is the identity.
    static void
    main(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, 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 long
    word(long[][] matrix, int r, int cw, int bits)
    Returns a specified word from a matrix in compact representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BITS

      public static final int BITS
      The number of bits of state of the generator.
      See Also:
    • twoToBitsMinus1

      public static final BigInteger twoToBitsMinus1
      The period of the generator (2BITS − 1).
    • factor

      public static final BigInteger[] factor
      Factors of the Fermat “primes” up to the eleventh (22048 + 1).
    • cofactor

      public static final BigInteger[] cofactor
      An array of cofactors. Entry 0 ≤ i < numCofactors contains twoToBitsMinus1 divided by factor[i]. Note that some entries can be null if BITS is less then 4096.
    • numCofactors

      public static final int numCofactors
      The actual number of valid entries in cofactor.
    • left

      public static long[][] left
      64x64 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 by word(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 column i can be retrieved as row[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 x and y.
    • 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 x and y in 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 is x2i (0 ≤ iBITS).
      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 m is the identity matrix.
      See Also:
    • mPow

      public static long[][] mPow(long[][][] q, 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 by quad(long[][]).
      e - an exponent smaller than or equal to 2BITS.
      Returns:
      the matrix whose array of quadratures is q raised to exponent e.
      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 m has 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

      public static void main(String[] arg)