Package edu.rit.util

Class DefaultRandom

java.lang.Object
edu.rit.util.Random
edu.rit.util.DefaultRandom
All Implemented Interfaces:
Serializable

public class DefaultRandom extends Random
Class DefaultRandom provides a default pseudorandom number generator (PRNG) designed for use in parallel scientific programming. To create an instance of class DefaultRandom, either use the DefaultRandom() constructor, or use the static getInstance(long) method in class Random.

Class DefaultRandom generates random numbers by hashing successive counter values. The seed initializes the counter. The hash function is defined in W. Press et al., Numerical Recipes: The Art of Scientific Computing, Third Edition (Cambridge University Press, 2007), page 352. The hash function applied to the counter value i is:

x := 3935559000370003845 * i + 2691343689449507681 (mod 264)
x := x xor (x right-shift 21)
x := x xor (x left-shift 37)
x := x xor (x right-shift 4)
x := 4768777513237032717 * x (mod 264)
x := x xor (x left-shift 20)
x := x xor (x right-shift 41)
x := x xor (x left-shift 5)
Return x

(The shift and arithmetic operations are all performed on unsigned 64-bit numbers.)

Version:
30-Mar-2008
Author:
Alan Kaminsky
See Also:
  • Constructor Details

    • DefaultRandom

      public DefaultRandom(long seed)
      Construct a new PRNG with the given seed. Any seed value is allowed.
      Parameters:
      seed - Seed.
  • Method Details

    • setSeed

      public void setSeed(long seed)
      Set this PRNG's seed.

      Note: Depending on the PRNG algorithm, certain seed values may not be allowed. See the PRNG algorithm subclass for further information. Set this PRNG's seed. Any seed value is allowed.

      Specified by:
      setSeed in class Random
      Parameters:
      seed - Seed.
    • next

      protected long next()
      Return the next 64-bit pseudorandom value in this PRNG's sequence.
      Specified by:
      next in class Random
      Returns:
      Pseudorandom value.
    • next

      protected long next(long skip)
      Return the 64-bit pseudorandom value the given number of positions ahead in this PRNG's sequence. Return the 64-bit pseudorandom value the given number of positions ahead in this PRNG's sequence.
      Specified by:
      next in class Random
      Parameters:
      skip - Number of positions to skip, assumed to be > 0.
      Returns:
      Pseudorandom value.