Tabnine Logo
ThreadLocalRandom
Code IndexAdd Tabnine to your IDE (free)

How to use
ThreadLocalRandom
in
org.glassfish.grizzly.utils

Best Java code snippets using org.glassfish.grizzly.utils.ThreadLocalRandom (Showing top 20 results out of 315)

origin: javaee/grizzly

    protected ThreadLocalRandom initialValue() {
      return new ThreadLocalRandom();
    }
};
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed {@code double} value
 * between 0 (inclusive) and the specified value (exclusive).
 *
 * @param n the bound on the random number to be returned.  Must be
 *        positive.
 * @return the next value
 * @throws IllegalArgumentException if n is not positive
 */
public double nextDouble(double n) {
  if (n <= 0)
    throw new IllegalArgumentException("n must be positive");
  return nextDouble() * n;
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public int nextInt(int least, int bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextInt(bound - least) + least;
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value
 * between 0 (inclusive) and the specified value (exclusive).
 *
 * @param n the bound on the random number to be returned.  Must be
 *        positive.
 * @return the next value
 * @throws IllegalArgumentException if n is not positive
 */
public long nextLong(long n) {
  if (n <= 0)
    throw new IllegalArgumentException("n must be positive");
  // Divide n by two until small enough for nextInt. On each
  // iteration (at most 31 of them but usually much less),
  // randomly choose both whether to include high bit in result
  // (offset) and whether to continue with the lower vs upper
  // half (which makes a difference only if odd).
  long offset = 0;
  while (n >= Integer.MAX_VALUE) {
    int bits = next(2);
    long half = n >>> 1;
    long nextn = ((bits & 2) == 0) ? half : n - half;
    if ((bits & 1) == 0)
      offset += n - nextn;
    n = nextn;
  }
  return offset + nextInt((int) n);
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public long nextLong(long least, long bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextLong(bound - least) + least;
}
origin: org.mule.glassfish.grizzly/grizzly-framework

  randomYields = ThreadLocalRandom.current();
if (randomYields.nextInt(CHAINED_SPINS) == 0)
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value
 * between 0 (inclusive) and the specified value (exclusive).
 *
 * @param n the bound on the random number to be returned.  Must be
 *        positive.
 * @return the next value
 * @throws IllegalArgumentException if n is not positive
 */
public long nextLong(long n) {
  if (n <= 0)
    throw new IllegalArgumentException("n must be positive");
  // Divide n by two until small enough for nextInt. On each
  // iteration (at most 31 of them but usually much less),
  // randomly choose both whether to include high bit in result
  // (offset) and whether to continue with the lower vs upper
  // half (which makes a difference only if odd).
  long offset = 0;
  while (n >= Integer.MAX_VALUE) {
    int bits = next(2);
    long half = n >>> 1;
    long nextn = ((bits & 2) == 0) ? half : n - half;
    if ((bits & 1) == 0)
      offset += n - nextn;
    n = nextn;
  }
  return offset + nextInt((int) n);
}
origin: org.glassfish.grizzly/grizzly-websockets-server

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public long nextLong(long least, long bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextLong(bound - least) + least;
}
origin: org.glassfish.grizzly/grizzly-websockets-server

/**
 * Returns a pseudorandom, uniformly distributed value
 * between 0 (inclusive) and the specified value (exclusive).
 *
 * @param n the bound on the random number to be returned.  Must be
 *        positive.
 * @return the next value
 * @throws IllegalArgumentException if n is not positive
 */
public long nextLong(long n) {
  if (n <= 0)
    throw new IllegalArgumentException("n must be positive");
  // Divide n by two until small enough for nextInt. On each
  // iteration (at most 31 of them but usually much less),
  // randomly choose both whether to include high bit in result
  // (offset) and whether to continue with the lower vs upper
  // half (which makes a difference only if odd).
  long offset = 0;
  while (n >= Integer.MAX_VALUE) {
    int bits = next(2);
    long half = n >>> 1;
    long nextn = ((bits & 2) == 0) ? half : n - half;
    if ((bits & 1) == 0)
      offset += n - nextn;
    n = nextn;
  }
  return offset + nextInt((int) n);
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public double nextDouble(double least, double bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextDouble() * (bound - least) + least;
}
origin: javaee/grizzly

    protected ThreadLocalRandom initialValue() {
      return new ThreadLocalRandom();
    }
};
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public long nextLong(long least, long bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextLong(bound - least) + least;
}
origin: org.glassfish.grizzly/grizzly-websockets-server

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public int nextInt(int least, int bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextInt(bound - least) + least;
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value
 * between 0 (inclusive) and the specified value (exclusive).
 *
 * @param n the bound on the random number to be returned.  Must be
 *        positive.
 * @return the next value
 * @throws IllegalArgumentException if n is not positive
 */
public long nextLong(long n) {
  if (n <= 0)
    throw new IllegalArgumentException("n must be positive");
  // Divide n by two until small enough for nextInt. On each
  // iteration (at most 31 of them but usually much less),
  // randomly choose both whether to include high bit in result
  // (offset) and whether to continue with the lower vs upper
  // half (which makes a difference only if odd).
  long offset = 0;
  while (n >= Integer.MAX_VALUE) {
    int bits = next(2);
    long half = n >>> 1;
    long nextn = ((bits & 2) == 0) ? half : n - half;
    if ((bits & 1) == 0)
      offset += n - nextn;
    n = nextn;
  }
  return offset + nextInt((int) n);
}
origin: org.glassfish.grizzly/grizzly-http-server-core

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public double nextDouble(double least, double bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextDouble() * (bound - least) + least;
}
origin: org.glassfish.grizzly/grizzly-core

    protected ThreadLocalRandom initialValue() {
      return new ThreadLocalRandom();
    }
};
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public long nextLong(long least, long bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextLong(bound - least) + least;
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value between the
 * given least value (inclusive) and bound (exclusive).
 *
 * @param least the least value returned
 * @param bound the upper bound (exclusive)
 * @return the next value
 * @throws IllegalArgumentException if least greater than or equal
 * to bound
 */
public int nextInt(int least, int bound) {
  if (least >= bound)
    throw new IllegalArgumentException();
  return nextInt(bound - least) + least;
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed value
 * between 0 (inclusive) and the specified value (exclusive).
 *
 * @param n the bound on the random number to be returned.  Must be
 *        positive.
 * @return the next value
 * @throws IllegalArgumentException if n is not positive
 */
public long nextLong(long n) {
  if (n <= 0)
    throw new IllegalArgumentException("n must be positive");
  // Divide n by two until small enough for nextInt. On each
  // iteration (at most 31 of them but usually much less),
  // randomly choose both whether to include high bit in result
  // (offset) and whether to continue with the lower vs upper
  // half (which makes a difference only if odd).
  long offset = 0;
  while (n >= Integer.MAX_VALUE) {
    int bits = next(2);
    long half = n >>> 1;
    long nextn = ((bits & 2) == 0) ? half : n - half;
    if ((bits & 1) == 0)
      offset += n - nextn;
    n = nextn;
  }
  return offset + nextInt((int) n);
}
origin: javaee/grizzly

/**
 * Returns a pseudorandom, uniformly distributed {@code double} value
 * between 0 (inclusive) and the specified value (exclusive).
 *
 * @param n the bound on the random number to be returned.  Must be
 *        positive.
 * @return the next value
 * @throws IllegalArgumentException if n is not positive
 */
public double nextDouble(double n) {
  if (n <= 0)
    throw new IllegalArgumentException("n must be positive");
  return nextDouble() * n;
}
org.glassfish.grizzly.utilsThreadLocalRandom

Javadoc

A random number generator isolated to the current thread. Like the global java.util.Random generator used by the java.lang.Math class, a ThreadLocalRandom is initialized with an internally generated seed that may not otherwise be modified. When applicable, use of ThreadLocalRandom rather than shared Random objects in concurrent programs will typically encounter much less overhead and contention. Use of ThreadLocalRandom is particularly appropriate when multiple tasks (for example, each a ForkJoinTask) use random numbers in parallel in thread pools.

Usages of this class should typically be of the form: ThreadLocalRandom.current().nextX(...) (where X is Int, Long, etc). When all usages are of this form, it is never possible to accidently share a ThreadLocalRandom across multiple threads.

This class also provides additional commonly used bounded random generation methods.

Most used methods

  • <init>
    Constructor called only by localRandom.initialValue.
  • next
  • nextDouble
    Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bo
  • nextInt
    Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bo
  • nextLong
    Returns a pseudorandom, uniformly distributed value between the given least value (inclusive) and bo
  • current
    Returns the current thread's ThreadLocalRandom.

Popular in Java

  • Reactive rest calls using spring rest template
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • setScale (BigDecimal)
  • getSupportFragmentManager (FragmentActivity)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • JLabel (javax.swing)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now