List of usage examples for org.apache.commons.lang.math RandomUtils nextInt
public static int nextInt(Random random, int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), from the given Random sequence.
From source file:com.fengduo.bee.commons.core.utils.Identities.java
public final static String getVehicleCode() { Random random = new Random(); return DateFormatUtils.format(new Date(), PURE_MIDDLE_DATE_TIME_FORMAT_STR) + RandomUtils.nextInt(random, 10) + RandomUtils.nextInt(random, 10); }
From source file:com.intel.cosbench.driver.util.OperationPicker.java
public String pickOperation(Random random) { int r = RandomUtils.nextInt(random, 100) + 1; for (Map.Entry<Integer, String> entry : ops.entrySet()) if (r <= entry.getKey()) return entry.getValue(); throw new IllegalStateException(); }
From source file:com.intel.cosbench.driver.generator.UniformIntGenerator.java
@Override public int next(Random random, int idx, int all) { int range = upper - lower + 1; int base = range / all; int extra = range % all; int offset = base * (idx - 1) + (extra >= idx - 1 ? idx - 1 : extra); int segment = base + (extra >= idx ? 1 : 0); int value = RandomUtils.nextInt(random, segment); value += offset + lower;// w w w . j av a2 s.c o m return value; }
From source file:com.intel.cosbench.driver.generator.RandomInputStream.java
public RandomInputStream(long size, Random random, boolean isRandom, boolean hashCheck) { super(size);/*from w w w. j a va 2 s. c om*/ this.hashCheck = hashCheck; try { this.util = new HashUtil(); } catch (NoSuchAlgorithmException e) { logger.error("Alogrithm not found", e); } this.hashLen = this.util.getHashLen(); if (size <= hashLen) { logger.warn("The size is too small to embed checksum, will ignore integrity checking."); this.hashCheck = false; this.util = null; this.hashLen = 0; } this.size = size; buffer = new byte[SIZE]; if (isRandom) for (int i = 0; i < SIZE; i++) buffer[i] = (byte) (RandomUtils.nextInt(random, 26) + 'a'); }
From source file:com.intel.cosbench.driver.generator.HistogramIntGenerator.java
@Override public int next(Random random) { final int next = RandomUtils.nextInt(random, totalWeight); for (Bucket bucket : buckets) { if (next <= bucket.cumulativeWeight) { return bucket.gen.next(random); }/*from www .j a va2 s . c om*/ } return 0; }
From source file:com.intel.cosbench.driver.agent.AuthAgent.java
private void sleepForSometime() { Random random = workerContext.getRandom(); int time = (10 + RandomUtils.nextInt(random, 40)) * 100; try {//from www . j av a2 s . c o m Thread.sleep(time); } catch (InterruptedException e) { throw new AuthInterruptedException(e); } Logger logger = getMissionLogger(); logger.debug("has waited for {} ms, will make a new attempt", time); }