Example usage for java.lang Math random

List of usage examples for java.lang Math random

Introduction

In this page you can find the example usage for java.lang Math random.

Prototype

public static double random() 

Source Link

Document

Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0 .

Usage

From source file:Main.java

public static void getTop(ArrayList<Double> array, ArrayList<Integer> rankList, int i) {
    int index = 0;
    HashSet<Integer> scanned = new HashSet<Integer>();
    Double max = Double.MIN_VALUE;
    for (int m = 0; m < i && m < array.size(); m++) {
        max = Double.MIN_VALUE;/*from  w ww .j  ava  2s  . co  m*/
        for (int no = 0; no < array.size(); no++) {
            if (!scanned.contains(no)) {
                if (array.get(no) > max) {
                    index = no;
                    max = array.get(no);
                } else if (array.get(no).equals(max) && Math.random() > 0.5) {
                    index = no;
                    max = array.get(no);
                }
            }
        }
        if (!scanned.contains(index)) {
            scanned.add(index);
            rankList.add(index);
        }
        //System.out.println(m + "\t" + index);
    }
}

From source file:org.jfree.chart.demo.DeviationRendererDemo3.java

private static XYDataset createDataset() {
    YIntervalSeries series1 = new YIntervalSeries("Band A");
    YIntervalSeries series2 = new YIntervalSeries("Band B");
    YIntervalSeries series3 = new YIntervalSeries("Band C");
    Object obj = new Quarter(1, 2005);
    double d = 0.0D;
    for (int i = 0; i <= 12; i++) {
        d += (Math.random() - 0.5D) * 15D;
        series1.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, d + 10D, Math.max(50D, d + 30D));
        series2.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, d - 10D, d + 10D);
        series3.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, Math.min(-50D, d - 30D), d - 10D);
        obj = ((RegularTimePeriod) (obj)).next();
    }//  w w w .ja  v  a2s.co  m

    YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series2);
    dataset.addSeries(series3);
    return dataset;
}

From source file:FlagComm.java

public void run() {
    for (int i = 0; i < 5; i++) {
        while (isValid) {
            Thread.yield();/*ww  w .  j ava  2 s.c  om*/
        }
        theValue = (int) (Math.random() * 256);
        System.out.println("sending " + theValue);
        isValid = true;
    }
}

From source file:com.weib.concert.CDPlayer.java

public void playShuffle() {
    this.cd.pull();
    for (int i = 0; i < 20; i++) {
        int index = (int) Math.floor(Math.random() * (double) this.cd.getTrackNumber());
        this.cd.play(index);
    }// w  w w  . ja v  a2  s.co  m
    this.cd.push();
}

From source file:de.blizzy.documentr.TestUtil.java

public static Page createRandomPage(String parentPagePath) {
    Page page = Page.fromText(String.valueOf(Math.random() * Long.MAX_VALUE),
            String.valueOf(Math.random() * Long.MAX_VALUE));
    TestPageUtil.setParentPagePath(page, parentPagePath);
    return page;/*from   w w  w .j a  v  a2  s. c om*/
}

From source file:Main.java

/** Returns a random number from the specified range 
 * @param min the smallest value that should occur when randomly generating numbers 
 * @param max the largest value that should occur when randomly generating numbers 
 * @return a random number between min and max. If min is larger than max, an exception will be thrown! */
public static int randomNumberBetweenIntervals(int min, int max) {
    if (min >= max) {
        throw new IllegalArgumentException("The minimum bound cannot be larger or equal to the maximum bound!");
    }/*from  ww  w  .  j a v  a  2 s .  co  m*/

    return min + (int) (Math.random() * ((max - min) + 1));
}

From source file:org.jfree.chart.demo.BoxAndWhiskerChartDemo1.java

@SuppressWarnings("rawtypes")
private static List createValueList(double d, double d1, int i) {
    ArrayList<Double> arraylist = new ArrayList<Double>();
    for (int j = 0; j < i; j++) {
        double d2 = d + Math.random() * (d1 - d);
        arraylist.add(new Double(d2));
    }//from   ww w .  j a  va  2 s.  c om

    return arraylist;
}

From source file:Pipe.java

public void run() {
    byte value;/*from w  ww.ja  v a  2  s.  com*/

    try {
        for (int i = 0; i < 5; i++) {
            value = (byte) (Math.random() * 256);
            System.out.print("About to send " + value + ".. ");
            out.write(value);
            System.out.println("..sent..");
            Thread.sleep((long) (Math.random() * 1000));
        }
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Hypnosis1.java

public Hypnosis1(int numberOfSegments) {
    int numberOfCoordinates = numberOfSegments * 4 + 2;
    coordinates = new int[numberOfCoordinates];
    deltas = new int[numberOfCoordinates];
    for (int i = 0; i < numberOfCoordinates; i++) {
        coordinates[i] = (int) (Math.random() * 300);
        deltas[i] = (int) (Math.random() * 4 + 3);
        if (deltas[i] > 4)
            deltas[i] = -(deltas[i] - 3);
    }/*from  w ww .j a  v  a2s  .  c o  m*/
    paint = new GradientPaint(0, 0, Color.blue, 20, 10, Color.red, true);

    Thread t = new Thread(this);
    t.start();
}

From source file:org.jfree.chart.demo.YIntervalChartDemo1.java

private static IntervalXYDataset createDataset() {
    double d = 100D;
    YIntervalSeries yintervalseries = new YIntervalSeries("Series 1");
    for (int i = 0; i < 100; i++) {
        d += Math.random() - 0.48999999999999999D;
        yintervalseries.add(i, d, d - 3D, d + 3D);
    }/* w w  w  . ja v  a 2  s . c o  m*/

    YIntervalSeriesCollection yintervalseriescollection = new YIntervalSeriesCollection();
    yintervalseriescollection.addSeries(yintervalseries);
    return yintervalseriescollection;
}