List of usage examples for org.apache.commons.lang3 RandomUtils nextDouble
public static double nextDouble(final double startInclusive, final double endInclusive)
Returns a random double within the specified range.
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:hu.unimiskolc.iit.distsys.BuiltInCloudProvider.java
@Override public void capacityChanged(ResourceConstraints newCapacity, List<PhysicalMachine> affectedCapacity) { final boolean newRegistration = myProvidedService.isRegisteredHost(affectedCapacity.get(0)); if (!newRegistration) { try {/* w w w .j a v a 2s .c o m*/ for (PhysicalMachine pm : affectedCapacity) { // For every lost PM we buy a new one. myProvidedService .registerHost(ExercisesBase.getNewPhysicalMachine(RandomUtils.nextDouble(2, 5))); } } catch (Exception e) { throw new RuntimeException(e); } } }
From source file:com.boozallen.cognition.ingest.storm.bolt.logging.LogRecordDateBolt.java
boolean shouldSample() { double dice = RandomUtils.nextDouble(0, 1); return dice <= sample; }
From source file:com.mtnfog.test.entity.utils.EntityUtils.java
/** * Creates a random entity./* w ww.j a v a 2 s .c om*/ * @param type The entity's {@link String class}. * @return A random entity. */ public static Entity createRandomEntity(String type) { final int entityLength = RandomUtils.nextInt(4, 25); Entity entity = new Entity(); entity.setText(RandomStringUtils.randomAlphabetic(entityLength)); entity.setConfidence(RandomUtils.nextDouble(0, 1)); entity.setLanguageCode("en"); entity.setSpan(new Span(3, 5)); entity.setType(type); return entity; }
From source file:com.mtnfog.test.entity.utils.EntityUtils.java
/** * Creates a random entity./*from www. jav a 2 s.c o m*/ * @param type The entity's {@link String class}. * @param minConfidence The minimum value of the confidence range. * @param maxConfidence The maximum value of the confidence range. * @return A random entity. */ public static Entity createRandomEntity(String type, double minConfidence, double maxConfidence) { final int entityLength = RandomUtils.nextInt(4, 25); Entity entity = new Entity(); entity.setText(RandomStringUtils.randomAlphabetic(entityLength)); entity.setConfidence(RandomUtils.nextDouble(minConfidence, maxConfidence)); entity.setLanguageCode("en"); entity.setSpan(new Span(3, 5)); entity.setType(type); return entity; }
From source file:cpcc.vvrte.services.task.AcoTspSimpleTest.java
@Test(dataProvider = "wreckedCostMatrixDataprovider") public void shouldThrowExceptionOnInvalidMatrixDimenstions(int w, int h) { double[][] costMatrix = new double[w][h]; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { costMatrix[i][j] = RandomUtils.nextDouble(0.0, 10.0); }//from ww w . j a v a 2s .com } try { AcoTspSimple.calculateBestPath(costMatrix, 1000, 3); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException e) { assertThat(e).hasMessage("Cost matrix heigth and width must be equal!"); } }
From source file:com.mtnfog.test.entity.utils.EntityUtils.java
/** * Creates a random person entity./*from w w w . ja v a 2 s .c om*/ * @return A random person {@link Entity entity}. */ public static Entity createRandomPersonEntity() { final int entityLength = RandomUtils.nextInt(4, 25); Entity entity = new Entity(); entity.setText(RandomStringUtils.randomAlphabetic(entityLength)); entity.setConfidence(RandomUtils.nextDouble(0, 1)); entity.setLanguageCode("en"); entity.setSpan(new Span(3, 5)); entity.setType("person"); entity.setEnrichments(createRandomEnrichments()); entity.setContext("context"); entity.setDocumentId("documentId"); return entity; }
From source file:cpcc.vvrte.services.task.AcoTspSimple.java
/** * @param costMatrix the cost matrix.//ww w .ja v a2s.c o m * @param pheromoneTrails the pheromone trails. * @return the path. */ private static List<Integer> generatePath(double[][] costMatrix, double[][] pheromoneTrails) { // int current = (int) (costMatrix.length * Math.random()); int current = RandomUtils.nextInt(0, costMatrix.length); List<Integer> used = new ArrayList<Integer>(); used.add(current); while (used.size() < costMatrix.length) { double sumWeight = doSumWeight(costMatrix, pheromoneTrails, used, current); // double rndValue = Math.random() * sumWeight; double rndValue = RandomUtils.nextDouble(0, sumWeight); current = findSumWeight(costMatrix, pheromoneTrails, used, current, rndValue); used.add(current); } return used; }
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:com.mtnfog.test.entity.utils.EntityUtils.java
/** * Creates a random person entity./*from w ww .ja v a 2 s . co m*/ * @param text The text of the entity. * @return A random person {@link Entity entity}. */ public static Entity createRandomPersonEntity(String text) { Entity entity = new Entity(); entity.setText(text); entity.setConfidence(RandomUtils.nextDouble(0, 1)); entity.setLanguageCode("en"); entity.setSpan(new Span(3, 5)); entity.setType("person"); return entity; }