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

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

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

Random.next介绍

[英]Returns a pseudo-random uniformly distributed int value of the number of bits specified by the argument bits as described by Donald E. Knuth in The Art of Computer Programming, Volume 2: Seminumerical Algorithms, section 3.2.1.

Most applications will want to use one of this class' convenience methods instead.
[中]返回由参数位指定的位数的伪随机均匀分布int值,如Donald E.Knuth在《计算机编程技术》第2卷:半数值算法,第3.2.1节中所述。
大多数应用程序都希望使用此类的便利方法。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code boolean}.
 */
public boolean nextBoolean() {
  return next(1) != 0;
}

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

java.lang.Thread.State: RUNNABLE
 at java.util.Random.next(Random.java:189)
 at java.util.Random.nextInt(Random.java:239)
 at sun.misc.Hashing.randomHashSeed(Hashing.java:254)
 at java.util.HashMap.<init>(HashMap.java:255)
 at java.util.HashMap.<init>(HashMap.java:297)

代码示例来源:origin: robovm/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code int}.
 */
public int nextInt() {
  return next(32);
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code long}.
 */
public long nextLong() {
  return ((long) next(32) << 32) + next(32);
}

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

public class MyRandom extends Random {
  public MyRandom() {}
  public MyRandom(int seed) { super(seed); }

  public int nextNonNegative() {
    return next(Integer.SIZE - 1);
  }
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code double}
 * in the half-open range [0.0, 1.0).
 */
public double nextDouble() {
  return ((((long) next(26) << 27) + next(27)) / (double) (1L << 53));
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code float}
 * in the half-open range [0.0, 1.0).
 */
public float nextFloat() {
  return (next(24) / 16777216f);
}

代码示例来源:origin: robovm/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code int}
 * in the half-open range [0, n).
 */
public int nextInt(int n) {
  if (n <= 0) {
    throw new IllegalArgumentException("n <= 0: " + n);
  }
  if ((n & -n) == n) {
    return (int) ((n * (long) next(31)) >> 31);
  }
  int bits, val;
  do {
    bits = next(31);
    val = bits % n;
  } while (bits - val + (n - 1) < 0);
  return val;
}

代码示例来源:origin: freenet/fred

@Override
  protected synchronized int next(int bits) {
    return super.next(bits);
  }
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code double}
 * in the half-open range [0.0, 1.0).
 */
public double nextDouble() {
  return ((((long) next(26) << 27) + next(27)) / (double) (1L << 53));
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code boolean}.
 */
public boolean nextBoolean() {
  return next(1) != 0;
}

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

class MyRandom extends Random {
  public short nextShort() {
    return (short) next(16); // give me just 16 bits.
  }
  public short nextNonNegativeShort() {
    return (short) next(15); // give me just 15 bits.
  }
}

short s = myRandom.nextShort();

代码示例来源:origin: ibinti/bugvm

/**
 * Returns a pseudo-random uniformly distributed {@code double}
 * in the half-open range [0.0, 1.0).
 */
public double nextDouble() {
  return ((((long) next(26) << 27) + next(27)) / (double) (1L << 53));
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code int}.
 */
public int nextInt() {
  return next(32);
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Returns a pseudo-random uniformly distributed {@code double}
 * in the half-open range [0.0, 1.0).
 */
public double nextDouble() {
  return ((((long) next(26) << 27) + next(27)) / (double) (1L << 53));
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns a pseudo-random uniformly distributed {@code float}
 * in the half-open range [0.0, 1.0).
 */
public float nextFloat() {
  return (next(24) / 16777216f);
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns a pseudo-random uniformly distributed {@code long}.
 */
public long nextLong() {
  return ((long) next(32) << 32) + next(32);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/** 
 * Simply use the method of the super class
 *
 * @param bits - random bits
 * @return the next pseudorandom value from this random number 
 * generator's sequence.
 */
protected int next(int bits) {return super.next(bits);}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns a pseudo-random uniformly distributed {@code boolean}.
 */
public boolean nextBoolean() {
  return next(1) != 0;
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns a pseudo-random uniformly distributed {@code float}
 * in the half-open range [0.0, 1.0).
 */
public float nextFloat() {
  return (next(24) / 16777216f);
}

相关文章