Loading...

Friday, 10 August 2012

Next Random number (Java code)

import java.util.Random;

class Random{
  private static final Random RAND = new Random();
  public static int nextRandomInt(int max) {
    int n = RAND.nextInt();
    return (n < 0 ? -n : n) % max;
  }
  public static int nextRandomInt() {
    int n = RAND.nextInt();
    return n < 0 ? -n : n;
  }
}

No comments:

Post a Comment