001package random; 002import java.util.Random; 003 004public class Util { 005 private Util() {} 006 static private Random RANDOM = new Random(); 007 008 /** doubles that differ by less than EPSILON should be considered equals */ 009 static public final double EPSILON = 1e-9; 010 static public boolean isEquals(double x, double y) { 011 return Math.abs(x-y) <= EPSILON; 012 } 013 static public boolean isLessOrEquals(double x, double y) { 014 return (x-y) <= EPSILON; 015 } 016 static public boolean isLess(double x, double y) { 017 return (x-y) < -EPSILON; 018 } 019 020 static public void setRandomSeed(long seed) { 021 RANDOM.setSeed(seed); 022 } 023 static public double nextRandom(double min, double max) { 024 if (Util.isLess(max,min)) 025 throw new IllegalArgumentException(max + " is smaller than " + min); 026 return min + ((RANDOM.nextDouble()) * (max - min)); 027 } 028}