Codota Logo
ThreadLocalRandom.next
Code IndexAdd Codota to your IDE (free)

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

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

  • Common ways to obtain ThreadLocalRandom
private void myMethod () {
ThreadLocalRandom t =
  • Codota Iconnew ThreadLocalRandom()
  • Smart code suggestions by Codota
}
origin: org.glassfish.grizzly/grizzly-core

/**
 * 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 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 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 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 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 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 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 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 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 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.mule.glassfish.grizzly/grizzly-framework

/**
 * 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 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);
}
org.glassfish.grizzly.utilsThreadLocalRandomnext

Javadoc

Returns a pseudorandom, uniformly distributed double value between 0 (inclusive) and the specified value (exclusive).

Popular methods of ThreadLocalRandom

  • <init>
    Constructor called only by localRandom.initialValue.
  • 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
  • scheduleAtFixedRate (Timer)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • getSharedPreferences (Context)
  • KeyStore (java.security)
    This class represents an in-memory collection of keys and certificates. It manages two types of entr
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • JComboBox (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now