Example usage for org.apache.commons.lang3 RandomUtils nextFloat

List of usage examples for org.apache.commons.lang3 RandomUtils nextFloat

Introduction

In this page you can find the example usage for org.apache.commons.lang3 RandomUtils nextFloat.

Prototype

public static float nextFloat(final float startInclusive, final float endInclusive) 

Source Link

Document

Returns a random float within the specified range.

Usage

From source file:example.client.CamelMongoJmsStockClient.java

@SuppressWarnings("resource")
public static void main(final String[] args) throws Exception {
    systemProps = loadProperties();/*from   www  .  j ava 2 s .c  o m*/
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
    ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
    List<Map<String, Object>> stocks = readJsonsFromMongoDB();
    for (Map<String, Object> stock : stocks) {
        stock.remove("_id");
        stock.remove("Earnings Date");
        camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")),
                ExchangePattern.InOnly, stock);
    }
    new Timer().schedule(new TimerTask() {
        @Override
        public void run() {
            Map<String, Object> aRandomStock = stocks.get(RandomUtils.nextInt(0, stocks.size()));
            aRandomStock.put("Price",
                    ((Double) aRandomStock.get("Price")) + RandomUtils.nextFloat(0.1f, 9.99f));
            camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")),
                    ExchangePattern.InOnly, aRandomStock);
        }
    }, 1000, 2000);
}

From source file:com.creactiviti.piper.core.taskhandler.random.Rogue.java

@Override
public Object handle(Task aTask) throws Exception {
    float nextFloat = RandomUtils.nextFloat(0, 1);
    float probabilty = aTask.getFloat("probabilty", 0.5f);
    Assert.isTrue(probabilty >= 0 && probabilty <= 1, "probability must be a value between 0 and 1");
    if (nextFloat <= probabilty) {
        throw new IllegalStateException("I'm a rogue exception");
    }//from   ww  w .j  a  va2 s .co m
    return null;
}

From source file:cn.codepub.redis.directory.Main.java

private static Document addDocument(int i) {
    Document document = new Document();
    document.add(new StringField("key1", "key" + i, Field.Store.YES));
    document.add(new IntField("key2", i * 100000, Field.Store.YES));
    document.add(new FloatField("key3", (float) i * 100000, Field.Store.YES));
    document.add(new LongField("key4", (long) i * 100000, Field.Store.YES));
    document.add(new DoubleField("key5", (double) i * 100000, Field.Store.YES));
    document.add(new TextField("key6", RandomStringUtils.randomAlphabetic(10), Field.Store.YES));
    document.add(new StringField("key7", RandomStringUtils.randomAlphabetic(5), Field.Store.YES));
    document.add(new BinaryDocValuesField("key8", new BytesRef(RandomStringUtils.randomAlphabetic(5))));
    document.add(new DoubleDocValuesField("key9", RandomUtils.nextDouble(0, 1000)));
    document.add(new FloatDocValuesField("key10", RandomUtils.nextFloat(0, 1000)));
    document.add(new LongField("key11", (long) i * 50000, Field.Store.YES));
    document.add(new IntField("key12", i * 50000, Field.Store.YES));
    document.add(new FloatField("key13", (float) i * 50000, Field.Store.YES));
    document.add(new DoubleField("key14", (double) i * 50000, Field.Store.YES));
    document.add(new StringField("key15", RandomStringUtils.randomAlphabetic(6), Field.Store.YES));
    return document;
}

From source file:TestLucene.java

private Document addDocument(int i) {
    Document document = new Document();
    document.add(new StringField("key1", "key" + i, Field.Store.YES));
    document.add(new IntField("key2", i * 100000, Field.Store.YES));
    document.add(new FloatField("key3", (float) i * 100000, Field.Store.YES));
    document.add(new LongField("key4", (long) i * 100000, Field.Store.YES));
    document.add(new DoubleField("key5", (double) i * 100000, Field.Store.YES));
    document.add(new TextField("key6", RandomStringUtils.randomAlphabetic(10), Field.Store.YES));
    document.add(new StringField("key7", RandomStringUtils.randomAlphabetic(5), Field.Store.YES));
    document.add(new BinaryDocValuesField("key8", new BytesRef(RandomStringUtils.randomAlphabetic(5))));
    document.add(new DoubleDocValuesField("key9", RandomUtils.nextDouble(0, 1000)));
    document.add(new FloatDocValuesField("key10", RandomUtils.nextFloat(0, 1000)));
    document.add(new LongField("key11", (long) i * 50000, Field.Store.YES));
    document.add(new IntField("key12", i * 50000, Field.Store.YES));
    document.add(new FloatField("key13", (float) i * 50000, Field.Store.YES));
    document.add(new DoubleField("key14", (double) i * 50000, Field.Store.YES));
    document.add(new StringField("key15", RandomStringUtils.randomAlphabetic(6), Field.Store.YES));
    return document;
}

From source file:org.wisepersist.jpa.JpaBaseEntityTest.java

/**
 * Tests {@link AbstractJpaBaseEntity#areEqual(float, float)} method, with same floats.
 *
 * @throws Exception If uncaught errors occur.
 *//*from ww  w .  java  2  s.  c  o m*/
@Test
public final void testAreEqual_shouldBeEqualBetweenTwoFloats() throws Exception {
    // Given
    final float minFloat = 100F;
    final float maxFloat = 200F;
    final float floatValue = RandomUtils.nextFloat(minFloat, maxFloat);
    final DummyEntity1 entity1 = new DummyEntity1();
    entity1.floatValue = floatValue;
    final DummyEntity1 entity2 = new DummyEntity1();
    entity2.floatValue = floatValue;

    // When
    final boolean equals = entity1.equals(entity2);

    // Then
    assertTrue(equals);
}

From source file:org.wisepersist.jpa.JpaBaseEntityTest.java

/**
 * Tests {@link AbstractJpaBaseEntity#areEqual(Date, Date)} method, with one date null.
 *
 * @throws Exception If uncaught errors occur.
 *//* ww w. j  a  va 2  s  .  c o  m*/
@Test
public final void testAreEqual_shouldNotBeEqualBetweenTwoFloatsIfOneIsZero() throws Exception {
    // Given
    final float minFloat = 100F;
    final float maxFloat = 200F;
    final float floatValue = RandomUtils.nextFloat(minFloat, maxFloat);
    final DummyEntity1 entity1 = new DummyEntity1();
    entity1.floatValue = floatValue;
    final DummyEntity1 entity2 = new DummyEntity1();
    entity2.floatValue = 0;

    // When
    final boolean equals = entity1.equals(entity2);

    // Then
    assertFalse(equals);
}