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:WaitComm.java

public void run() {
    for (int i = 0; i < 5; i++) {
        synchronized (this) {
            while (isValid) {
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }//from ww  w .j av  a2  s  .co  m
            }
        }
        theValue = (int) (Math.random() * 256);
        System.out.println("sending " + theValue);
        synchronized (this) {
            isValid = true;
            this.notify();
        }
    }
}

From source file:com.springinpractice.ch14.kite.sample.service.impl.Flakinator.java

public void simulateFlakiness() {
    if (up) {//from ww  w . ja  v  a2  s .  co m
        if (Math.random() < 0.05) {
            this.up = false;
        }
    } else {
        if (Math.random() < 0.2) {
            this.up = true;
        }
    }

    if (!up) {
        throw new RuntimeException("Oops, service down");
    }
}

From source file:email.cadastro.EmailCadastro.java

public String geraCodConfirmacao() {
    int random;//from   ww w. j  a  v a  2s.co  m
    String cod = "";
    boolean v = false;
    for (int i = 0; i < 8; i++) {
        v = false;
        do {
            random = (int) (Math.random() * 122);
            if (random >= 48 && random <= 57)
                v = true;
            else if (random >= 97 && random <= 122)
                v = true;
            else if (random >= 65 && random <= 90)
                v = true;
        } while (!v);
        //System.out.print((char) random + "");
        cod += (char) random;
    }
    //System.out.println(cod);

    return cod;
}

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

private static List<Double> 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));
    }/*w w  w. ja  va 2  s.c  om*/

    return arraylist;
}

From source file:com.phoenixst.plexus.examples.RandomGraphFactory.java

/**
 *  Creates a random graph with <code>n</code> nodes where each
 *  pair of nodes has probability <code>prob</code> of having an
 *  edge between them.//from  w  w w  .  j  av  a 2 s  . c om
 */
public static Graph createStandardGraph(int n, double prob) {
    if (prob < 0.0 || prob > 1.0) {
        throw new IllegalArgumentException("Probability must be between 0.0 and 1.0, inclusive.");
    }
    Graph graph = new DefaultGraph(new EmptyGraph(n));
    for (int head = 1; head < n; head++) {
        Object headNode = new Integer(head);
        for (int tail = 0; tail < head; tail++) {
            if (Math.random() < prob) {
                graph.addEdge(null, new Integer(tail), headNode, true);
            }
        }
    }
    return graph;
}

From source file:net.duckling.ddl.util.EncodeUtil.java

private static int getRandomNumber() {
    double a = Math.random() * 10;
    a = Math.ceil(a);/*from www .  java  2s .  c om*/
    int decimal = new Double(a).intValue();
    return decimal % 10;
}

From source file:TimerBasedAnimation.java

public void reset(int w, int h) {
    maxSize = w / 10;
    setXY(maxSize * Math.random(), w, h);
}

From source file:org.example.fis.MyTransformer.java

public String transform() {
    // let's return a random string
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 3; i++) {
        int number = (int) (Math.round(Math.random() * 1000) % 10);
        char letter = (char) ('0' + number);
        buffer.append(letter);/*w w  w .j  a  v  a 2  s. com*/
    }
    return buffer.toString();
}

From source file:boutiqueenligne.service.CalculPrixTotalAvecPromoService.java

public void generationCodePromo(int valeur, TypeCode TypeCode) {
    CodePromo code = new CodePromo();
    String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    String codeg = "";
    for (int x = 0; x < 5; x++) {
        int i = (int) Math.floor(Math.random() * 36);
        codeg += chars.charAt(i);/*  www .  j  a  v  a 2  s .  c o m*/
    }
    code.setCode(codeg);
    code.setType(TypeCode);
    code.setValeur(valeur);
    codePromoService.save(code);
}

From source file:com.b5m.user.frame.util.DateUtils.java

public static String getRandomInteger() {
    int temp = (int) (Math.random() * 9999);
    return String.valueOf(temp);
}