List of usage examples for java.lang Math random
public static double random()
From source file:com.hortonworks.pso.data.generator.fields.StringField.java
private int getStringSize() { if (diff == 0) { return min; } else {//from w w w .ja v a 2 s .c o m double ran = Math.random(); long vector = Math.round(diff * ran); return (int) (min + vector); } }
From source file:classifiers.Simpleclassifier.java
@Override public void bootstrapvalidierungsmenge(Instances inst) { if (inst.numAttributes() != 0) { int[] hilf = new int[inst.numInstances()]; for (int i = 0; i < inst.numInstances(); i++) { int a = ((int) (Math.random() * inst.numInstances())); hilf[i] = a;//w ww . ja va2s .com } Modelsindexen = EliminiereDopelt(hilf); Modelmenge = new Instances(inst, Modelsindexen.length); for (int i = 0; i < Modelsindexen.length; i++) { Modelmenge.add(new Instance(inst.instance(Modelsindexen[i]))); } validierungsindexen = new int[inst.numInstances() - Modelsindexen.length]; validierungsmenge = new Instances(Modelmenge, validierungsindexen.length); for (int i = 0, j = 0; i < inst.numInstances() && j < validierungsindexen.length; i++, j++) { if (!(HasSet(Modelsindexen, i))) { validierungsindexen[j] = i; validierungsmenge.add(inst.instance(validierungsindexen[j])); } } } }
From source file:com.redhat.rhn.frontend.graphing.test.GraphGeneratorTest.java
private TimeSeriesData[] getTestTimeSeriesData(String metric, int size) { TimeSeriesData[] tsd = new TimeSeriesData[size]; for (int i = 0; i < tsd.length; i++) { Calendar start = Calendar.getInstance(); start.roll(Calendar.HOUR, -3); start.add(Calendar.MINUTE, (i * 5)); Float rnd = new Float(Math.random() * 10); tsd[i] = new TimeSeriesData("1-2-test", rnd, start.getTime(), metric); }/* ww w. j a v a2s. c o m*/ return tsd; }
From source file:Main.java
/** * Positions the specified frame at a random location on the screen while ensuring that the * entire frame is visible (provided that the frame is smaller than the screen). * * @param frame the frame.//from w ww . j a v a 2 s . c o m */ public static void positionFrameRandomly(final Window frame) { positionFrameOnScreen(frame, Math.random(), Math.random()); }
From source file:io.liveoak.testtools.AbstractTestCase.java
private static String randomName() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 9; i++) { int num = (int) (35 * Math.random()); if (num > 9) { sb.append((char) ('a' + num - 9)); } else {//from w w w . j a v a2 s .co m sb.append((char) ('0' + num)); } } return sb.toString(); }
From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.chartdemo.MultiAPIChartDemo.java
/** * Creates a sample dataset for the demo. * * @return A sample dataset./*from w ww . j av a 2 s . co m*/ */ private PieDataset createSampleDataset() { final DefaultPieDataset result = new DefaultPieDataset(); // cheating: java has a higher chance to be the best language :) result.setValue("Java", new Integer((int) (Math.random() * 200))); result.setValue("Visual Basic", new Integer((int) (Math.random() * 50))); result.setValue("C/C++", new Integer((int) (Math.random() * 100))); result.setValue("PHP", new Integer((int) (Math.random() * 50))); result.setValue("Perl", new Integer((int) (Math.random() * 100))); return result; }
From source file:BufferedImageThread.java
AnimationCanvas() { setBackground(Color.green);//from ww w . ja v a 2 s .co m setSize(450, 400); image = getToolkit().getImage("largeJava2sLogo.gif"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1); try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading image."); } if (image.getWidth(this) == -1) { System.out.println("No gif file"); System.exit(0); } rotate = (int) (Math.random() * 360); scale = Math.random() * 1.5; scaleDirection = DOWN; xi = 50.0; yi = 50.0; }
From source file:org.limewire.activation.impl.ActivationCommunicatorImpl.java
/** * Returns a random number as a String. */ private static String getRandomToken() { return String.valueOf(Math.random()).substring(2); }
From source file:edu.uci.ics.jung.algorithms.layout.BalloonLayout.java
protected void setPolars(List<V> kids, Point2D parentLocation, double parentRadius) { int childCount = kids.size(); if (childCount == 0) return;/*from ww w. ja v a 2s. c o m*/ // handle the 1-child case with 0 limit on angle. double angle = Math.max(0, Math.PI / 2 * (1 - 2.0 / childCount)); double childRadius = parentRadius * Math.cos(angle) / (1 + Math.cos(angle)); double radius = parentRadius - childRadius; double rand = Math.random(); for (int i = 0; i < childCount; i++) { V child = kids.get(i); double theta = i * 2 * Math.PI / childCount + rand; radii.put(child, childRadius); PolarPoint pp = new PolarPoint(theta, radius); polarLocations.put(child, pp); Point2D p = PolarPoint.polarToCartesian(pp); p.setLocation(p.getX() + parentLocation.getX(), p.getY() + parentLocation.getY()); locations.put(child, p); setPolars(new ArrayList<V>(graph.getChildren(child)), p, childRadius); } }
From source file:com.ciphertool.genetics.algorithms.mutation.LiberalMutationAlgorithm.java
/** * Performs a genetic mutation of a random Gene of the supplied Chromosome * /*from w ww . j av a2 s . c o m*/ * @param chromosome * the Chromosome to mutate */ private Integer mutateRandomGene(Chromosome chromosome, List<Integer> geneIndices) { int randomIndex; // We don't want to reuse an index, so loop until we find a new one int attempts = 0; do { randomIndex = (int) (Math.random() * chromosome.getGenes().size()); attempts++; if (attempts >= MAX_FIND_ATTEMPTS) { if (log.isDebugEnabled()) { log.debug("Unable to find a previously unused Gene index after " + attempts + " attempts. Returning null."); } return null; } } while (geneIndices.contains(randomIndex)); mutateGene(chromosome, randomIndex); chromosomeHelper.resizeChromosome(chromosome); return randomIndex; }