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.cds.pcrj.consultaMoeda.MyTransformer.java

public String transform() {
    // lets 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);//from  w  ww  .j  a  v a  2s .c o m
    }
    return buffer.toString();
}

From source file:dtu.ds.warnme.utils.RandomUtils.java

public static float randomFloat(float min, float max) {
    Float f = (float) (min + Math.random() * (max - min + 1));
    return Float.valueOf(new DecimalFormat("#.##").format(f));
}

From source file:com.apress.prospringintegration.corespring.aop.RandomItemGenerator.java

public Item getRandomItem() {
    Item item = new Item();
    item.setCost((float) Math.random() * 250);
    item.setDescription("random item");

    int inum = (int) Math.round(Math.random() * (itemNames.length - 1));
    item.setId(inum);/*from   w w w  . j  a va2s . c o  m*/
    item.setName(itemNames[inum]);

    return item;
}

From source file:edu.uci.ics.jung.algorithms.generators.random.MixedRandomGraphGenerator.java

/**
 * Returns a random mixed-mode graph.  Starts with a randomly generated 
 * Barabasi-Albert (preferential attachment) generator 
 * (4 initial vertices, 3 edges added at each step, and num_vertices - 4 evolution steps).
 * Then takes the resultant graph, replaces random undirected edges with directed
 * edges, and assigns random weights to each edge.
 */// w w w  .  ja va2s  .co m
public static <V, E> Graph<V, E> generateMixedRandomGraph(Factory<Graph<V, E>> graphFactory,
        Factory<V> vertexFactory, Factory<E> edgeFactory, Map<E, Number> edge_weights, int num_vertices,
        boolean parallel, Set<V> seedVertices) {
    int seed = (int) (Math.random() * 10000);
    BarabasiAlbertGenerator<V, E> bag = new BarabasiAlbertGenerator<V, E>(graphFactory, vertexFactory,
            edgeFactory, 4, 3, //false, parallel, 
            seed, seedVertices);
    bag.evolveGraph(num_vertices - 4);
    Graph<V, E> ug = bag.create();

    // create a SparseMultigraph version of g
    Graph<V, E> g = graphFactory.create();
    //new SparseMultigraph<V, E>();
    for (V v : ug.getVertices()) {
        g.addVertex(v);
    }

    // randomly replace some of the edges by directed edges to 
    // get a mixed-mode graph, add random weights

    for (E e : ug.getEdges()) {
        V v1 = ug.getEndpoints(e).getFirst();
        V v2 = ug.getEndpoints(e).getSecond();

        E me = edgeFactory.create();
        g.addEdge(me, v1, v2, Math.random() < .5 ? EdgeType.DIRECTED : EdgeType.UNDIRECTED);
        edge_weights.put(me, Math.random());
    }

    return g;
}

From source file:com.apress.prospringintegration.corespring.aop.PurchaseOrderProcessorImpl.java

public Receipt processPurchaseOrder(PurchaseOrder order) {
    order.setProcessedTime(Calendar.getInstance().getTime());
    Receipt receipt = new Receipt();
    receipt.setPurchaseAmt(order.getItemCost());
    receipt.setAuthcode(Math.round(Math.random() * 2000000));

    return receipt;
}

From source file:Main.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 source file:com.cssweb.android.connect.ConnPool.java

public static JSONObject servicePasswordLogin(String custno, String password) {
    StringBuffer sb = new StringBuffer();
    sb.append("https://jy.njzq.cn/service/login/Login/mobileClientServLogin.do");
    sb.append("?clientNo=");
    sb.append(custno);/*  ww w.j  ava2 s  . c  o  m*/
    sb.append("&password=");
    sb.append(password);
    sb.append("&ram=");
    sb.append(Math.random());
    Log.i("?>>>>>url>>>>>>>", sb.toString());
    return Conn.execute(sb.toString());
}

From source file:com.uber.stream.kafka.mirrormaker.controller.utils.KafkaStarterUtils.java

public static KafkaServerStartable startServer(final int port, final int brokerId, final String zkStr,
        final Properties configuration) {
    // Create the ZK nodes for Kafka, if needed
    int indexOfFirstSlash = zkStr.indexOf('/');
    if (indexOfFirstSlash != -1) {
        String bareZkUrl = zkStr.substring(0, indexOfFirstSlash);
        String zkNodePath = zkStr.substring(indexOfFirstSlash);
        ZkClient client = new ZkClient(bareZkUrl);
        client.createPersistent(zkNodePath, true);
        client.close();/*  www  .  ja  v a 2s . c o  m*/
    }

    File logDir = new File("/tmp/kafka-" + Double.toHexString(Math.random()));
    logDir.mkdirs();

    configureKafkaPort(configuration, port);
    configureZkConnectionString(configuration, zkStr);
    configureBrokerId(configuration, brokerId);
    configureKafkaLogDirectory(configuration, logDir);
    KafkaConfig config = new KafkaConfig(configuration);

    KafkaServerStartable serverStartable = new KafkaServerStartable(config);
    serverStartable.startup();

    return serverStartable;
}

From source file:Main.java

private void loadArray() {
    for (int i = 0; i < numbers.length; i++) {
        numbers[i] = min + (int) (Math.random() * ((max - min) + 1));
    }/*from   w  w w  .  java2 s .com*/
}

From source file:Clipping.java

public void actionPerformed(ActionEvent e) {
    int w = 400;/*w ww.  ja  va 2  s. co  m*/
    int h = 400;

    if (x < 0) {
        delta[0] = Math.random() % 4 + 5;
    } else if (x > w - radius) {
        delta[0] = -(Math.random() % 4 + 5);
    }

    if (y < 0) {
        delta[1] = Math.random() % 4 + 5;
    } else if (y > h - radius) {
        delta[1] = -(Math.random() % 4 + 5);
    }

    x += delta[0];
    y += delta[1];

    repaint();
}