List of usage examples for java.util Random nextDouble
public double nextDouble()
From source file:nova.core.util.math.Vector2DUtil.java
/** * @return Creates a random unit vector// www . ja va 2 s .co m */ public static Vector2D random() { Random random = new Random(); return new Vector2D(random.nextDouble(), random.nextDouble()).scalarMultiply(2).subtract(ONE); }
From source file:util.PositionHelper.java
/** * Creates a latitude in portugal// w w w . jav a2 s .co m * * @return a latitude as double */ public static Double createLatitude() { Random r = new Random(); Double latitude = (r.nextDouble() * -360.0) + 180.0; boolean latidudeBool = true; while (latidudeBool) { if (latitude < Constants.NORTH_BORDER && latitude > Constants.SOUTH_BORDER) { latidudeBool = false; } else { latitude = (r.nextDouble() * -360.0) + 180.0; } } return latitude; }
From source file:util.PositionHelper.java
/** * Creates a longitude in portugal// w w w . j a va 2s. c o m * * @return a longitude as double */ public static Double createLongitude() { Random r = new Random(); Double longitude = (r.nextDouble() * -180.0) + 90; boolean longitudeBool = true; while (longitudeBool) { if (longitude < Constants.EAST_BORDER && longitude > Constants.WEST_BORDER) { longitudeBool = false; } else { longitude = (r.nextDouble() * -180.0) + 90; } } return longitude; }
From source file:edu.berkeley.sparrow.examples.ProtoFrontendAsync.java
public static double generateInterarrivalDelay(Random r, double lambda) { double u = r.nextDouble(); return -Math.log(u) / lambda; }
From source file:nova.core.util.math.Vector3DUtil.java
/** * @return Creates a random unit vector/*from w w w .j a v a 2s. c om*/ */ public static Vector3D random() { Random random = new Random(); return new Vector3D(random.nextDouble(), random.nextDouble(), random.nextDouble()).scalarMultiply(2) .subtract(ONE); }
From source file:com.caseystella.analytics.distribution.RotationTest.java
public static DataPoint nextDataPoint(Random r, long ts, long delta, List<DataPoint> points) { double val = r.nextDouble() * 1000; DataPoint dp = (new DataPoint(ts, val, null, "foo")); if (points != null) { points.add(dp);//from w w w .j ava 2 s. c om } ts += delta; return dp; }
From source file:rsa_matrices.Helpers.java
public static double[][] generateMatrix(int rows, int columns) { double result[][]; result = new double[rows][columns]; for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { Random random = new Random(); result[row][col] = 2 * random.nextDouble(); }//from w w w . j av a2s . co m } return result; }
From source file:com.insightml.math.distributions.DiscreteDistribution.java
public static int sample(final double[] discreteDistribution, final Random random) { final double rand = random.nextDouble(); double sum = 0; for (int i = 0; i < discreteDistribution.length; ++i) { sum += discreteDistribution[i];/*from w ww .ja va2 s . c o m*/ if (rand <= sum) { return i; } } throw new IllegalStateException(rand + " / " + sum); }
From source file:org.ensor.fftmusings.rnn.GravesLSTMCharModellingExample.java
/** * Given a probability distribution over discrete classes, sample from the * distribution and return the generated class index. * * @param distribution Probability distribution over classes. Must sum to * 1.0/*from w w w.j a v a 2 s . c o m*/ */ private static int sampleFromDistribution(double[] distribution, Random rng) { double d = rng.nextDouble(); double sum = 0.0; for (int i = 0; i < distribution.length; i++) { sum += distribution[i]; if (d <= sum) { return i; } } //Should never happen if distribution is a valid probability distribution throw new IllegalArgumentException("Distribution is invalid? d=" + d + ", sum=" + sum); }
From source file:com.oculusinfo.ml.spark.unsupervised.TestDPMeans.java
public static void genTestData(int k) { PrintWriter writer;/*from www.jav a 2s . co m*/ try { writer = new PrintWriter("test.txt", "UTF-8"); // each class size is equal int classSize = 1000000 / k; double stdDev = 30.0; // generate k classes of data points using a normal distribution with random means and fixed std deviation for (int i = 0; i < k; i++) { Random rnd = new Random(); double meanLat = rnd.nextDouble() * 400.0; double meanLon = rnd.nextDouble() * 400.0; // randomly generate a dataset of lat, lon points for (int j = 0; j < classSize; j++) { double x = rnd.nextGaussian() * stdDev + meanLat; double y = rnd.nextGaussian() * stdDev + meanLon; writer.println(x + "," + y); } } writer.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } }