List of usage examples for org.apache.commons.math3.random RandomDataGenerator nextInt
public int nextInt(int lower, int upper) throws NumberIsTooLargeException
From source file:RandomGenTest.java
public static void main(String[] args) { RandomDataGenerator rand = new RandomDataGenerator(); Map<Object, Integer> map = new HashMap(); for (int i = 0; i < 101; i++) map.put(i, 0);//w w w .j a v a2 s . c o m Map<Object, Integer> user = new HashMap(); for (int i = 0; i < 100; i++) { int age = rand.nextInt(0, 100); /*int age = (int) rand.nextGaussian(50, 10D); if ((age > 100) || (age < 0)) { age = rand.nextInt(0, 100); }*/ user.put(i, age); } for (int i = 0; i < 100000; i++) { //int age = rand.nextInt(0, 100); /*int age = (int) rand.nextGaussian(50, 10D); if ((age > 100) || (age < 0)) { age = rand.nextInt(0, 100); }*/ //Seq //map.put(user.get(i%100), map.get(user.get(i%100))+1); //Rand int j = rand.nextInt(0, 99); map.put(user.get(j), map.get(user.get(j)) + 1); } display(map); }
From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.RandomListGenerator.java
/** * @param args/*ww w .j a v a2 s .c o m*/ */ public static void main(String[] args) { System.out.println("Have started list generator."); File outFile = new File("/tmp/randomList.txt"); RandomDataGenerator generator = new RandomDataGenerator(); int listSize = 503; // The size of the array / list to be generated // The Strings to be randomized String[] strings = { "0DE968C9-7309-C481-58F7-AB6CDB1011EF", "5C1D9939-136A-55DE-FD0E-61D8204E17C9", "B936DA83-8A45-E9F0-2EAE-D75F5C232E78" }; try { for (int j = 0; j < listSize; j++) { FileUtils.write(outFile, strings[generator.nextInt(0, strings.length - 1)] + "\n", true); // Append to file } } catch (IOException e) { System.err.println("IOException in main."); e.printStackTrace(); } System.out.println("Have finished list generator."); }
From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.IncomingLogGenerator.java
/** * @param args/*from w ww . j a v a2s .com*/ */ public static void main(String[] args) { System.out.println("Have started IncomingSMSGenerator."); File outFile = new File("/tmp/logs/incomingSMS.csv"); RandomDataGenerator randomDataImpl = new RandomDataGenerator(); String randomStrFile = "/tmp/random.txt"; List<String> randomStrings = new ArrayList<>(); int randStrLength = 0; long startDate = 1412380800; // Unix time in seconds for Oct 4 2014 long stopDate = 1420070340; // Unix time for in seconds Dec 31 2014 SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2011-06-01 00:16:45" List<String> shortcodeUuids = new ArrayList<>(); shortcodeUuids.add("094def52-bc18-4a9e-9b84-c34cc6476c75"); shortcodeUuids.add("e9570c5d-0cc4-41e5-81df-b0674e9dda1e"); shortcodeUuids.add("a118c8ea-f831-4288-986d-35e22c91fc4d"); shortcodeUuids.add("a2688d72-291b-470c-8926-31a903f5ed0c"); shortcodeUuids.add("9bef62f6-e682-4efd-98e9-ca41fa4ef993"); int shortcodeCount = shortcodeUuids.size() - 1; try { randomStrings = FileUtils.readLines(new File(randomStrFile)); randStrLength = randomStrings.size(); for (int j = 0; j < 30000; j++) { FileUtils.write(outFile, // shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|" // Destination UUID.randomUUID().toString() + "|" // Unique Code + randomDataImpl.nextLong(new Long("254700000000").longValue(), new Long("254734999999").longValue()) + "|" // Origin + shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|" + randomStrings.get(randomDataImpl.nextInt(0, randStrLength - 1)) + "|" // Message + "N|" // deleted + dateFormatter.format( new Date(randomDataImpl.nextLong(startDate, stopDate) * 1000)) + "\n", // smsTime true); // Append to file } } catch (IOException e) { System.err.println("IOException in main."); e.printStackTrace(); } System.out.println("Have finished IncomingSMSGenerator."); }
From source file:com.milaboratory.core.alignment.AlignerTest.java
public static void testLocalRandom(AlignmentScoring sc) { int its = TestUtil.its(100, 10000); Well19937c rdi = new Well19937c(1234112L); RandomDataGenerator generator = new RandomDataGenerator(rdi); for (int i = 0; i < its; ++i) { NucleotideSequence sq1 = randomSequence(NucleotideSequence.ALPHABET, rdi, 100, 300); int length = generator.nextInt(10, 30); int from = generator.nextInt(0, sq1.size() - length - 1); NucleotideSequence needle = sq1.getRange(from, from + length); Alignment<NucleotideSequence> r = Aligner.alignLocal(sc, sq1, needle); Assert.assertEquals(from, r.getSequence1Range().getFrom()); assertTrue(r.getAbsoluteMutations().isEmpty()); }//from w w w . j a v a2s . c o m }
From source file:de.anycook.user.User.java
public static String getRandomUserpic() { RandomDataGenerator random = new RandomDataGenerator(); return String.format("userpic%d.png", random.nextInt(1, 3)); }
From source file:com.cloudera.oryx.ml.param.Unordered.java
/** * @param rdg random number generator to use * @return a value chosen at random from given values *///from w w w. j a va 2 s .c om @Override public T getRandomValue(RandomDataGenerator rdg) { return values.get(rdg.nextInt(0, values.size() - 1)); }
From source file:ijfx.ui.filter.FilterFactoryTest.java
@Override public void start(Stage primaryStage) throws Exception { Collection<MetaDataOwner> ownerList = new ArrayList<>(); String[] keyName = { "Name", "Date", "Amount" }; for (int i = 0; i != 200; i++) { ownerList.add(new OwnerTest()); }//from w w w. j a v a 2s .c o m MetaDataFilterFactory factory = new DefaultMetaDataFilterFactory(); RandomDataGenerator generator = new RandomDataGenerator(); int index = generator.nextInt(0, 2); MetaDataOwnerFilter filter = factory.generateFilter(ownerList, keyName[1]); Scene scene = new Scene((Parent) filter.getContent()); primaryStage.setScene(scene); primaryStage.show(); }
From source file:com.cloudera.oryx.ml.param.DiscreteRange.java
/** * @param rdg random number generator to use * @return a hyperparameter value chosen uniformly at random from the range */// www . j a v a 2s. c om @Override public Integer getRandomValue(RandomDataGenerator rdg) { if (max == min) { return min; } return rdg.nextInt(min, max); }
From source file:com.hurence.logisland.processor.GenerateRandomRecord.java
@Override public Collection<Record> process(final ProcessContext context, final Collection<Record> collection) { final String schemaContent = context.getPropertyValue(OUTPUT_SCHEMA).asString(); final DataGenerator dataGenerator = new DataGenerator(schemaContent); final RandomDataGenerator randomData = new RandomDataGenerator(); final int minEventsCount = context.getPropertyValue(MIN_EVENTS_COUNT).asInteger(); final int maxEventsCount = context.getPropertyValue(MAX_EVENTS_COUNT).asInteger(); final int eventsCount = randomData.nextInt(minEventsCount, maxEventsCount); logger.debug("generating {} events in [{},{}]", eventsCount, minEventsCount, maxEventsCount); List<Record> outRecords = new ArrayList<>(); for (int i = 0; i < eventsCount; i++) { try {//from w ww . j av a 2 s . c om outRecords.add(dataGenerator.generateRandomRecord(RECORD_TYPE)); } catch (Exception e) { logger.error("problem while generating random event from avro schema {}", e); } } return outRecords; }
From source file:com.milaboratory.core.alignment.BandedAlignerTest.java
@Test public void testAddedLeftRandom1() throws Exception { int its = its(1000, 100000); NucleotideSequence seq1, seq2;/*from w w w.j a v a 2 s . c o m*/ int offset1, offset2, length1, length2, added1, added2; Alignment<NucleotideSequence> la; RandomDataGenerator random = new RandomDataGenerator(new Well19937c()); for (int i = 0; i < its; ++i) { seq1 = randomSequence(NucleotideSequence.ALPHABET, random, 80, 84); seq2 = randomSequence(NucleotideSequence.ALPHABET, random, 80, 84); offset1 = random.nextInt(0, seq1.size() - 10); offset2 = random.nextInt(0, seq2.size() - 10); length1 = random.nextInt(1, seq1.size() - offset1); length2 = random.nextInt(1, seq2.size() - offset2); added1 = random.nextInt(0, length1); added2 = random.nextInt(0, length2); la = BandedAligner.alignLeftAdded(LinearGapAlignmentScoring.getNucleotideBLASTScoring(), seq1, seq2, offset1, length1, added1, offset2, length2, added2, 1); assertTrue(la.getSequence1Range().getFrom() == offset1 || la.getSequence2Range().getFrom() == offset2); assertTrue(la.getSequence1Range().getFrom() <= offset1 + added1); assertTrue(la.getSequence2Range().getFrom() <= offset2 + added2); assertAlignment(la, seq2); } }