/** * Randomize a {@code long} value in the given range [min, max]. */ public long nextLong(long min, long max) { if (min > max) { throw new IllegalArgumentException(MIN_MAX_ERROR); } return min + nextLong(max - min + 1); }
/** * Randomize a {@code long} value between 0 (inclusive) and the specified value (exclusive). */ public long nextLong(long l) { if (l <= 0) { throw new IllegalArgumentException("l must be greater than 0!"); } long rand = nextLong(); if (rand == Long.MIN_VALUE) { rand++; } return Math.abs(rand) % l; }
/** * Randomize a valid numeric string. * * @param length * The requested length of the string. */ public String nextNumericString(int length) { return Long.toString(nextLong( (long) Math.pow(10, length - 1), (long) (Math.pow(10, length) - 1))); }
private List<GlusterClientInfo> getClientList(int listSize) { ArrayList<GlusterClientInfo> list = new ArrayList<>(); for(int i=0; i < listSize; i++) { GlusterClientInfo clientInfo = new GlusterClientInfo(); clientInfo.setBytesRead(RandomUtils.instance().nextLong()); clientInfo.setBytesWritten(RandomUtils.instance().nextLong()); clientInfo.setClientPort(RandomUtils.instance().nextInt()); clientInfo.setHostname(RandomUtils.instance().nextString(7)); list.add(clientInfo); } return list; }
private static VdsStatistics randomVdsStatistics() { RandomUtils random = RandomUtils.instance(); VdsStatistics vdsStatistics = new VdsStatistics(); vdsStatistics.setCpuIdle(random.nextDouble()); vdsStatistics.setCpuLoad(random.nextDouble()); vdsStatistics.setCpuSys(random.nextDouble()); vdsStatistics.setCpuUser(random.nextDouble()); vdsStatistics.setMemAvailable(random.nextLong()); vdsStatistics.setMemFree(random.nextLong()); vdsStatistics.setMemShared(random.nextLong()); vdsStatistics.setUsageCpuPercent(random.nextInt()); vdsStatistics.setUsageMemPercent(random.nextInt()); vdsStatistics.setUsageNetworkPercent(random.nextInt()); vdsStatistics.setCpuOverCommitTimeStamp(new Date(random.nextLong())); return vdsStatistics; }