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.falkonry.TestAddDataStream.java

/**
 * Should add narrow data to datastream in stream JSON format
 * @throws Exception/*  www  .  j a  va  2s.com*/
 */
@Test
public void addDataJsonStream() throws Exception {

    Datastream ds = new Datastream();
    ds.setName("Test-DS1-" + Math.random());

    TimeObject time = new TimeObject();
    time.setIdentifier("time");
    time.setFormat("iso_8601");
    time.setZone("GMT");

    Signal signal = new Signal();
    signal.setTagIdentifier("tag");
    signal.setValueIdentifier("value");
    signal.setDelimiter("_");
    signal.setIsSignalPrefix(false);

    Datasource dataSource = new Datasource();
    dataSource.setType("STANDALONE");

    Field field = new Field();
    field.setSiganl(signal);
    field.setTime(time);

    ds.setDatasource(dataSource);
    ds.setField(field);

    Datastream datastream = falkonry.createDatastream(ds);
    datastreams.add(datastream);

    Map<String, String> options = new HashMap<String, String>();

    File file = new File("res/data.json");
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
    InputStatus inputStatus = falkonry.addInputStream(datastream.getId(), byteArrayInputStream, options);
    Assert.assertEquals(inputStatus.getAction(), "ADD_DATA_DATASTREAM");
    Assert.assertEquals(inputStatus.getStatus(), "PENDING");
    Datastream datastream1 = falkonry.getDatastream(datastream.getId());
    Assert.assertEquals(datastream1.getId(), datastream.getId());
    Assert.assertEquals(datastream1.getName(), datastream.getName());
    Field field1 = datastream1.getField();
    Signal signal1 = field1.getSignal();
    Assert.assertEquals(signal1.getDelimiter(), signal.getDelimiter());
    Assert.assertEquals(signal1.getTagIdentifier(), signal.getTagIdentifier());
    Assert.assertEquals(signal1.getValueIdentifier(), signal.getValueIdentifier());
    Assert.assertEquals(signal1.getIsSignalPrefix(), signal.getIsSignalPrefix());
}

From source file:MainClass.java

int rnd(int limit) {
    return ((int) (Math.random() * limit));
}

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

public LBVip() {
    this.id = String.valueOf((int) (Math.random() * 10000));
    this.name = null;
    this.tenantId = null;
    this.netId = null;
    this.address = 0;
    this.protocol = 0;
    this.lbMethod = 0;
    this.port = 0;
    this.pools = new ArrayList<String>();
    this.sessionPersistence = false;
    this.connectionLimit = 0;
    this.address = 0;
    this.status = 0;

    this.proxyMac = MACAddress.valueOf(LB_PROXY_MAC);
}

From source file:graficarordenamiento.Graficador.java

public void crearBase(int cantidad) {
    int m = 0;//from ww  w . j ava 2  s .c  om
    for (int i = 0; i < cantidad; i++) {
        m = (int) (Math.random() * cantidad + 1);
        if (!lista.contains(m)) {
            lista.add(m);
        }
    }
}

From source file:com.romeikat.datamessie.core.base.util.sparsetable.SparseMultiTableTest.java

@Test
public void serializeAndDeserialize() throws Exception {

    final SparseMultiTable<Double, Double, Double> table = new SparseMultiTable<Double, Double, Double>();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
        final double rowHeader = Math.random();
        final double columnHeader = Math.random();
        final double value1 = Math.random();
        final double value2 = Math.random();
        table.putValue(rowHeader, columnHeader, value1);
        table.putValue(rowHeader, columnHeader, value2);
    }/*from ww  w.  java 2s .c  o m*/

    final byte[] serializedTable = SerializationUtils.serialize(table);
    @SuppressWarnings("unchecked")
    final SparseMultiTable<Double, Double, Double> deserializedTable = (SparseMultiTable<Double, Double, Double>) SerializationUtils
            .deserialize(serializedTable);

    assertEquals(table, deserializedTable);

}

From source file:com.romeikat.datamessie.core.base.util.sparsetable.SparseSingleTableTest.java

@Test
public void serializeAndDeserialize() throws Exception {

    final SparseSingleTable<Double, Double, Double> table = new SparseSingleTable<Double, Double, Double>();
    for (int i = 0; i < NUMBER_OF_ITERATIONS; i++) {
        final double rowHeader = Math.random();
        final double columnHeader = Math.random();
        final double value = Math.random();
        table.putValue(rowHeader, columnHeader, value);
    }/*from   w ww  . j  av  a2  s.c  o m*/

    final byte[] serializedTable = SerializationUtils.serialize(table);
    @SuppressWarnings("unchecked")
    final SparseSingleTable<Double, Double, Double> deserializedTable = (SparseSingleTable<Double, Double, Double>) SerializationUtils
            .deserialize(serializedTable);

    assertEquals(table, deserializedTable);

}

From source file:it.infn.ct.futuregateway.apiserver.utils.TestDataIT.java

/**
 * Create a random infrastructure.//  w w  w .  ja va  2  s  .c o  m
 * Data are randomly generated.
 *
 * @return The infrastructure
 */
public static Infrastructure createInfrastructure() {
    Infrastructure infra = new Infrastructure();
    infra.setName(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_STRING_LENGTH))));
    infra.setDescription(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_DESC_LENGTH))));
    infra.setEnabled(rnd.nextBoolean());
    List<Params> params = (List<Params>) new LinkedList<Params>();
    for (int i = 0; i < (int) (Math.random() * MAX_ENTITIES_IN_LIST); i++) {
        Params p = new Params();
        p.setDescription(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_DESC_LENGTH))));
        p.setName(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_STRING_LENGTH))));
        p.setValue(RandomStringUtils.randomAlphanumeric((int) (1 + (Math.random() * MAX_STRING_LENGTH))));
        params.add(p);
    }
    if (!params.isEmpty()) {
        infra.setParameters(params);
    }
    return infra;
}

From source file:com.github.jeromeroucou.javasignedurl.utils.SignedUrlUtils.java

/**
 * @return A random number to add some salt in hash encoding
 * @since 1.0/*from  w  w w.  java2  s  . co  m*/
 */
private static String getSomeSalt() {
    synchronized (SignedUrlUtils.class) {
        if (salt == null) {
            salt = String.valueOf(Math.random()).substring(2);
        }
    }
    return salt;
}

From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.DemandReport.java

/**
 * @param initiator//from   w  ww  . ja v a2s.c  o  m
 * @param name
 * @param epochNumber
 * @param stats
 */
public DemandReport(NodeIDType initiator, String name, int epochNumber, JSONObject stats) {
    super(initiator, ReconfigurationPacket.PacketType.DEMAND_REPORT, name, epochNumber);
    this.stats = stats;
    this.requestID = (long) (Math.random() * Long.MAX_VALUE);
}

From source file:us.putney.controllers.SampleServiceController.java

static Map getHero(String name) {
    Map<String, Object> hero = new HashMap<String, Object>();
    hero.put("name", name);
    hero.put("title", titles[(int) Math.floor(Math.random() * titles.length)]);
    hero.put("age", (int) (Math.random() * 100));
    List powers = new ArrayList();
    for (int i = 0; i < 1 + Math.random() * 3; i++) {
        powers.add(getPower());/*  w  w w  . j ava2 s  . c o  m*/
    }
    hero.put("powers", powers);
    return hero;
}