/** * Simple random number generator * Code adapted from OOP class slides. * @author Felipe Scrochio Custódio */ import java.util.Calendar; public class Random { private long p = 2147483648l; private long m = 843314861; private long a = 453816693; private long xi = 1023; /** * Returns a random number in the interval (0,1[ * @return Random number */ public double getRand() { xi = (a + m * xi) % p; double d = xi; return d / p; } /** * Returns a random int in the interval (0,max[ * @param max - Limit * @return Random number */ public int getIntRand(int max) { double d = getRand() * max; return (int) d; } /** * Allows changing the seed for the random number generator. * @param seed - the new value for the seed */ public void setSemente(int seed) { xi = seed; } /** * Constructor that allows setting the seed beforehand * @param k - Initial value for the seed */ public Random(int k) { xi = k; } /** * Constructor that uses a random seed, generated by getting the current time in the machine (millisseconds) */ public Random() { xi = Calendar.getInstance().getTimeInMillis(); } }