Example usage for java.util Random nextFloat

List of usage examples for java.util Random nextFloat

Introduction

In this page you can find the example usage for java.util Random nextFloat.

Prototype

public float nextFloat() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Usage

From source file:net.redwarp.library.database.test.MyClass.java

public MyClass() {
    mString = RandomStringUtils.randomAlphabetic(10);

    Random random = new Random();
    mFloat = random.nextFloat();
}

From source file:org.diorite.utils.math.DioriteRandomUtils.java

public static float getRandomFloat(final Random random, final float min, final float max)
        throws IllegalArgumentException {
    if (Float.compare(min, max) == 0) {
        return max;
    }/*from   w  w  w.ja  va  2s  .c om*/
    Validate.isTrue(max > min, "Max can't be smaller than min!");
    return (random.nextFloat() * (max - min)) + min;
}

From source file:com.controller.RandomController.java

@RequestMapping(value = "getRandom.htm", method = RequestMethod.GET)
public @ResponseBody String getRandom() {
    Random rnd = new Random();
    String result = "<br/>Response from controller " + rnd.nextFloat() * 100 + " time " + new Date().toString();
    return result;
}

From source file:org.apache.hadoop.hbase.io.hfile.TestHFileBlock.java

static int writeTestKeyValues(HFileBlock.Writer hbw, int seed, boolean includesMemstoreTS, boolean useTag)
        throws IOException {
    List<KeyValue> keyValues = new ArrayList<KeyValue>();
    Random randomizer = new Random(42l + seed); // just any fixed number

    // generate keyValues
    for (int i = 0; i < NUM_KEYVALUES; ++i) {
        byte[] row;
        long timestamp;
        byte[] family;
        byte[] qualifier;
        byte[] value;

        // generate it or repeat, it should compress well
        if (0 < i && randomizer.nextFloat() < CHANCE_TO_REPEAT) {
            row = keyValues.get(randomizer.nextInt(keyValues.size())).getRow();
        } else {//from   w  w  w  . j a  va  2  s. c o  m
            row = new byte[FIELD_LENGTH];
            randomizer.nextBytes(row);
        }
        if (0 == i) {
            family = new byte[FIELD_LENGTH];
            randomizer.nextBytes(family);
        } else {
            family = keyValues.get(0).getFamily();
        }
        if (0 < i && randomizer.nextFloat() < CHANCE_TO_REPEAT) {
            qualifier = keyValues.get(randomizer.nextInt(keyValues.size())).getQualifier();
        } else {
            qualifier = new byte[FIELD_LENGTH];
            randomizer.nextBytes(qualifier);
        }
        if (0 < i && randomizer.nextFloat() < CHANCE_TO_REPEAT) {
            value = keyValues.get(randomizer.nextInt(keyValues.size())).getValue();
        } else {
            value = new byte[FIELD_LENGTH];
            randomizer.nextBytes(value);
        }
        if (0 < i && randomizer.nextFloat() < CHANCE_TO_REPEAT) {
            timestamp = keyValues.get(randomizer.nextInt(keyValues.size())).getTimestamp();
        } else {
            timestamp = randomizer.nextLong();
        }
        if (!useTag) {
            keyValues.add(new KeyValue(row, family, qualifier, timestamp, value));
        } else {
            keyValues.add(new KeyValue(row, family, qualifier, timestamp, value,
                    new Tag[] { new Tag((byte) 1, Bytes.toBytes("myTagVal")) }));
        }
    }

    // sort it and write to stream
    int totalSize = 0;
    Collections.sort(keyValues, KeyValue.COMPARATOR);

    for (KeyValue kv : keyValues) {
        totalSize += kv.getLength();
        if (includesMemstoreTS) {
            long memstoreTS = randomizer.nextLong();
            kv.setMvccVersion(memstoreTS);
            totalSize += WritableUtils.getVIntSize(memstoreTS);
        }
        hbw.write(kv);
    }
    return totalSize;
}

From source file:org.standard.bestpratice.security.Secure.java

public String getSaltString() {
    String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    StringBuilder salt = new StringBuilder();
    Random rnd = new Random();
    while (salt.length() < 32) {
        int index = (int) (rnd.nextFloat() * SALTCHARS.length());
        salt.append(SALTCHARS.charAt(index));
    }//from ww  w. j a va 2 s.c o m
    String saltStr = salt.toString();
    return saltStr;

}

From source file:BufferTest.java

private float[] data(int elements) {
    float[] data = new float[elements];
    Random rng = new Random();

    for (int i = 0; i < data.length; i++) {
        data[i] = 100 * rng.nextFloat();
    }//w w  w  .ja  va2  s  .  c  o m

    return data;
}

From source file:net.futuredrama.jomaceld.circularpbexamples.ExampleFragments.Example1Fragment.java

public void setRandomProgress() {
    Random r = new Random();
    sb_progress.setProgress((int) (r.nextFloat() * 100));
}

From source file:com.orange.cepheus.cep.controller.ControllerIntegrationTest.java

@Test
public void postConfAndNotifyContext() throws Exception {
    //Config effectu dans le setup

    Random random = new Random(15);

    for (int i = 1; i < 100; i++) {

        float value = random.nextFloat();
        NotifyContext notifyContext = createNotifyContextTempSensor(value);

        mockMvc.perform(// w w w.j av  a2  s.  co  m
                post("/v1/notifyContext").content(json(mapping, notifyContext)).contentType(contentType))
                .andExpect(status().isOk());
    }

}

From source file:com.orange.cepheus.cep.controller.ControllerIntegrationTest.java

@Test
public void postConfAndUpdateContext() throws Exception {
    //Config effectu dans le setup

    Random random = new Random(15);

    for (int i = 1; i < 100; i++) {

        float value = random.nextFloat();
        UpdateContext updateContext = createUpdateContextTempSensor(value);

        mockMvc.perform(/*from   w w  w  . j  a  v  a  2 s . co  m*/
                post("/v1/updateContext").content(json(mapping, updateContext)).contentType(contentType))
                .andExpect(status().isOk());
    }

}

From source file:org.blockartistry.mod.DynSurround.client.footsteps.engine.implem.BasicAcoustic.java

private float randAB(final Random rng, final float a, final float b) {
    if (a >= b)
        return a;

    return a + rng.nextFloat() * (b - a);
}