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:com.ciphertool.genetics.algorithms.selection.modes.TournamentSelector.java

@Override
public int getNextIndex(List<Chromosome> individuals, Double totalFitness) {
    Collections.sort(individuals, fitnessComparator);

    for (int i = 0; i < individuals.size(); i++) {
        if (Math.random() <= selectionAccuracy) {
            return i;
        }/*w w  w  .  j  a va2 s  .c  o m*/
    }

    // return the least fit individual since it won the tournament
    return individuals.size() - 1;
}

From source file:com.awcoleman.ExampleJobSummaryLogWithOutput.utility.CreateBinaryDatafile.java

public String generateDatetime() {
    long offset = Timestamp.valueOf("2015-02-21 00:00:00").getTime();
    long end = Timestamp.valueOf("2015-02-24 00:00:00").getTime();
    long diff = end - offset + 1;
    Timestamp rand = new Timestamp(offset + (long) (Math.random() * diff));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss.SSS");

    return sdf.format(rand);
}

From source file:ColorsBeanInfo.java

private Color randomColor() {
        int r = (int) (255 * Math.random());
        int g = (int) (255 * Math.random());
        int b = (int) (255 * Math.random());
        return new Color(r, g, b);
    }//from   w  w  w .  ja v  a 2 s.c o  m

From source file:net.fenyo.mail4hotspot.web.GMailOAuthStep1Servlet.java

private String nonce() {
    return new Integer(new Double(Math.random() * 100000000).intValue()).toString();
}

From source file:Main.java

private ObservableList<XYChart.Series<String, Double>> getChartData() {
    double aValue = 10;
    double cValue = 20;
    ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList();
    Series<String, Double> aSeries = new Series<String, Double>();
    Series<String, Double> cSeries = new Series<String, Double>();
    aSeries.setName("a");
    cSeries.setName("C");

    for (int i = 2001; i < 2021; i++) {
        aSeries.getData().add(new XYChart.Data(Integer.toString(i), aValue));
        aValue = aValue + Math.random() * 100 - 50;
        cSeries.getData().add(new XYChart.Data(Integer.toString(i), cValue));
        cValue = cValue + Math.random() * 100 - 50;
    }/*ww w  . j  a va  2s  .  co m*/
    answer.addAll(aSeries, cSeries);
    return answer;
}

From source file:net.floodlightcontroller.loadbalancer.LBPool.java

public LBPool() {
    id = String.valueOf((int) (Math.random() * 10000));
    name = null;//from   w ww.ja va 2s.  c o m
    tenantId = null;
    netId = null;
    lbMethod = 0;
    protocol = 0;
    members = new ArrayList<String>();
    monitors = new ArrayList<String>();
    adminState = 0;
    status = 0;
    previousMemberIndex = -1;
}

From source file:Charts2D.java

public Charts2D() {
    super("2D Charts");
    setSize(720, 280);//from w w  w . j  ava2 s.co  m
    getContentPane().setLayout(new GridLayout(1, 3, 10, 0));
    getContentPane().setBackground(Color.white);

    int[] xData = new int[8];
    int[] yData = new int[8];
    for (int i = 0; i < xData.length; i++) {
        xData[i] = i;
        yData[i] = (int) (Math.random() * 100);
        if (i > 0)
            yData[i] = (yData[i - 1] + yData[i]) / 2;
    }

    JChart2D chart = new JChart2D(JChart2D.LineChart, xData.length, xData, yData, "Line Chart");
    chart.setStroke(new BasicStroke(5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
    chart.setLineColor(new Color(0, 28, 28));
    getContentPane().add(chart);

    chart = new JChart2D(JChart2D.ColumnChart, xData.length, xData, yData, "Column Chart");
    GradientPaint gp = new GradientPaint(0, 100, Color.white, 0, 300, Color.blue, true);
    chart.setGradient(gp);
    chart.setEffectIndex(JChart2D.Gradientffect);
    chart.setDrawShadow(true);
    getContentPane().add(chart);

    chart = new JChart2D(JChart2D.PieChart, xData.length, xData, yData, "Pie Chart");
    ImageIcon icon = new ImageIcon("largeJava2slogo.GIF");
    chart.setForegroundImage(icon.getImage());
    chart.setEffectIndex(JChart2D.ImageEffect);
    chart.setDrawShadow(true);
    getContentPane().add(chart);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);

    setVisible(true);
}

From source file:com.linkedin.pinot.common.utils.KafkaStarterUtils.java

public static KafkaServerStartable startServer(final int port, final int brokerId, final String zkStr,
        final Properties configuration) {
    return startServer(port, brokerId, zkStr, "/tmp/kafka-" + Double.toHexString(Math.random()), configuration);
}

From source file:Main.java

private ObservableList<XYChart.Series<Integer, Double>> getChartData() {
    double aValue = 1.56;
    double bValue = 1.06;
    ObservableList<XYChart.Series<Integer, Double>> answer = FXCollections.observableArrayList();
    Series<Integer, Double> aSeries = new Series<Integer, Double>();
    Series<Integer, Double> bSeries = new Series<Integer, Double>();
    aSeries.setName("A");
    bSeries.setName("B");
    for (int i = 2011; i < 2016; i++) {
        double diff = Math.random();
        aSeries.getData().add(new XYChart.Data(i, aValue, diff));
        aValue = aValue + 10 * diff - 5;
        diff = Math.random();//w  w w .j ava  2  s . c  om
        bSeries.getData().add(new XYChart.Data(i, bValue, diff));
        bValue = bValue + 10 * diff - 5;
        diff = Math.random();
    }
    answer.addAll(aSeries, bSeries);
    return answer;
}

From source file:bq.tutorial.netflix.hystrix.DynamicTest.java

@Test(invocationCount = 2000, threadPoolSize = 20)
public void testStatusRejected() {
    String commandName = "name" + (int) (Math.random() * 100);
    float failPercent = (float) Math.random();
    float timeoutPercent = (float) Math.random();
    int percentToBreakCircuit = (int) (Math.random() * 50 + 50);

    String queryString = "?name=" + commandName + "&failPercent=" + failPercent + "&timeoutPercent="
            + timeoutPercent + "&percentToBreakCircuit=" + percentToBreakCircuit;

    RestTemplate client = new RestTemplate();
    String result = client.getForObject("http://localhost:8080/netflix_hystrix/mvc/dynamic" + queryString,
            String.class);
    System.out.println(result);//  w w  w.j  a va  2  s.c  om
}