FileDocCategorySizeDatePackage
RandomNos.javaAPI DocExample636Fri Mar 31 21:43:52 BST 2000None

RandomNos.java

//Random number class
import java.util.*;
class RandomNos {
  static final Random r;
  
  static {
  // a class constructor won't do the job if no instance of
  // RandomNos is called
    
    r = new Random();//not the same every time
  }

  
 
  public static int binRand() {
  // Returns 0 or 1
    float holdR = r.nextFloat();
    if(holdR >0.5) {
      return 0;
    }
    else {
      return 1;
    }
  }

  public static int rangeRand(int range) {
  // returns a number in the range 0..range-1
    return Math.abs(r.nextInt()) % range;
  }

  public static float floatRand() {
  //returns 0..1.0
    return r.nextFloat();
  }

}