java.util.Random.initialScramble()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(3.3k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中java.util.Random.initialScramble()方法的一些代码示例,展示了Random.initialScramble()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Random.initialScramble()方法的具体详情如下:
包路径:java.util.Random
类名称:Random
方法名:initialScramble

Random.initialScramble介绍

暂无

代码示例

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Creates a new random number generator using a single {@code long} seed.
 * The seed is the initial value of the internal state of the pseudorandom
 * number generator which is maintained by method {@link #next}.
 *
 * <p>The invocation {@code new Random(seed)} is equivalent to:
 *  <pre> {@code
 * Random rnd = new Random();
 * rnd.setSeed(seed);}</pre>
 *
 * @param seed the initial seed
 * @see   #setSeed(long)
 */
public Random(long seed) {
  this.seed = initialScramble(seed);
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Creates a new random number generator using a single {@code long} seed.
 * The seed is the initial value of the internal state of the pseudorandom
 * number generator which is maintained by method {@link #next}.
 *
 * <p>The invocation {@code new Random(seed)} is equivalent to:
 *  <pre> {@code
 * Random rnd = new Random();
 * rnd.setSeed(seed);}</pre>
 *
 * @param seed the initial seed
 * @see   #setSeed(long)
 */
public Random(long seed) {
  this.seed = initialScramble(seed);
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Sets the seed of this random number generator using a single
 * {@code long} seed. The general contract of {@code setSeed} is
 * that it alters the state of this random number generator object
 * so as to be in exactly the same state as if it had just been
 * created with the argument {@code seed} as a seed. The method
 * {@code setSeed} is implemented by class {@code Random} by
 * atomically updating the seed to
 *  <pre>{@code (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)}</pre>
 * and clearing the {@code haveNextNextGaussian} flag used by {@link
 * #nextGaussian}.
 *
 * <p>The implementation of {@code setSeed} by class {@code Random}
 * happens to use only 48 bits of the given seed. In general, however,
 * an overriding method may use all 64 bits of the {@code long}
 * argument as a seed value.
 *
 * @param seed the initial seed
 */
synchronized public void setSeed(long seed) {
  this.seed = initialScramble(seed);
  haveNextNextGaussian = false;
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Sets the seed of this random number generator using a single
 * {@code long} seed. The general contract of {@code setSeed} is
 * that it alters the state of this random number generator object
 * so as to be in exactly the same state as if it had just been
 * created with the argument {@code seed} as a seed. The method
 * {@code setSeed} is implemented by class {@code Random} by
 * atomically updating the seed to
 *  <pre>{@code (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)}</pre>
 * and clearing the {@code haveNextNextGaussian} flag used by {@link
 * #nextGaussian}.
 *
 * <p>The implementation of {@code setSeed} by class {@code Random}
 * happens to use only 48 bits of the given seed. In general, however,
 * an overriding method may use all 64 bits of the {@code long}
 * argument as a seed value.
 *
 * @param seed the initial seed
 */
synchronized public void setSeed(long seed) {
  this.seed = initialScramble(seed);
  haveNextNextGaussian = false;
}

代码示例来源:origin: stackoverflow.com

public class RandomCustom extends Random{

  //You have to Override this aswell.
  @Override
  synchronized public void setSeed(long seed) {
    this.seed.set(initialScramble(seed));
    haveNextNextGaussian = false;
  }

  @Override
  protected int next(int bits){
    long oldseed, nextseed;
    AtomicLong seed = this.seed;
    do {
      oldseed = seed.get();
      nextseed = (oldseed * fact + constant) & modulus;
    } while (!seed.compareAndSet(oldseed, nextseed));
    return (int)(nextseed >>> (48 - bits));
  }
}

相关文章