Next random Int : Random « Development « Android






Next random Int

    
//package org.expressme.wireless.game;

import java.util.Random;

class Main {

  private static final Random RANDOM = new Random();

  /**
   * Generate random integer between 0(include) and max(exclude).
   */
  public static int nextRandomInt(int max) {
    int n = RANDOM.nextInt();
    return (n < 0 ? -n : n) % max;
  }

  /**
   * Generate random integer between 0(include) and Integer.MAX_VALUE.
   */
  public static int nextRandomInt() {
    int n = RANDOM.nextInt();
    return n < 0 ? -n : n;
  }
}

   
    
    
    
  








Related examples in the same category

1.Random Alphabet Maker
2.Random Xor Obfuscator
3.returns a random number among { 0 to count-1 }
4.Random Generator
5.Get Random Index