/** Creates a new random number generator. This constructor sets the seed of the random number generator to a value very likely * to be distinct from any other invocation of this constructor. * <p> * This implementation creates a {@link Random} instance to generate the initial seed. */ public RandomXS128 () { setSeed(new Random().nextLong()); }
public static String getAccessToken(HttpServletRequest request) { String accessToken = null; while (accessToken == null || accessToken.length() == 0) { long r0 = weakRandom ? (hashCode ^ Runtime.getRuntime().freeMemory() ^ random.nextInt() ^ (((long)request.hashCode()) << 32)) : random.nextLong(); long r1 = random.nextLong(); if (r0 < 0) r0 = -r0; if (r1 < 0) r1 = -r1; accessToken = Long.toString(r0, 36) + Long.toString(r1, 36); } return accessToken; } }
@Override public void nextTuple() { try { Thread.sleep(100); } catch (InterruptedException e) { // ignore } // tuple values are mapped with // metric, timestamp, value, Map of tagK/tagV respectively. collector.emit(Lists.newArrayList("device.temp", System.currentTimeMillis(), new Random().nextLong(), Collections.singletonMap("loc.id", new Random().nextInt() % 64 + ""))); } }
@Test public void testSubmitRandomSizeRequest() throws Exception { Random rn = new Random(); final long limit = 10 * 1024 * 1024; final int requestCount = 1 + (int) (rn.nextDouble() * 3); long n = rn.nextLong(); if (n < 0) { n = -n; } else if (n == 0) { n = 1; } long putsHeapSize = n % limit; long maxHeapSizePerRequest = putsHeapSize / requestCount; LOG.info("[testSubmitRandomSizeRequest] maxHeapSizePerRequest=" + maxHeapSizePerRequest + ", putsHeapSize=" + putsHeapSize); doSubmitRequest(maxHeapSizePerRequest, putsHeapSize); }
/** * @throws Exception If failed. */ @Test public void testShort() throws Exception { short val = (short)RND.nextLong(); out.writeShort(val); assertEquals(val, getShortByByteLE(out.internalArray())); assertEquals(val, in.readShort()); }
Rec1(Random r) { d1 = r.nextDouble(); d11 = r.nextDouble(); f2 = r.nextFloat(); f22 = r.nextFloat(); f3 = r.nextInt(); f33 = r.nextInt(); f4 = r.nextLong(); f44 = r.nextLong(); f5 = (byte) r.nextInt(); f55 = (byte) r.nextInt(); f6 = (short) r.nextInt(); f66 = (short) r.nextInt(); } }
@Override public void open(Configuration parameters) throws Exception { // this sink can only work with DOP 1 assertEquals(1, getRuntimeContext().getNumberOfParallelSubtasks()); long failurePosMin = (long) (0.4 * LINES_PER_FILE); long failurePosMax = (long) (0.7 * LINES_PER_FILE); elementsToFailure = (new Random().nextLong() % (failurePosMax - failurePosMin)) + failurePosMin; }
@Test public void clearMine_logs_map_sq_health_state_and_current_client_uuid_if_TRACE() { logging.setLevel(Level.TRACE); Map<String, TimestampedNodeHealth> map = new HashMap<>(); map.put(randomAlphanumeric(4), new TimestampedNodeHealth(randomNodeHealth(), random.nextLong())); doReturn(map).when(hazelcastMember).getReplicatedMap(MAP_SQ_HEALTH_STATE); String uuid = randomAlphanumeric(5); when(hazelcastMember.getUuid()).thenReturn(uuid); underTest.clearMine(); assertThat(logging.getLogs()).hasSize(1); assertThat(logging.hasLog(Level.TRACE, "Reading " + map + " and clearing for " + uuid)).isTrue(); }
private static void assertHashLongEquivalence(HashFunction hashFunction, Random random) { long l = random.nextLong(); assertEquals(hashFunction.hashLong(l), hashFunction.newHasher().putLong(l).hash()); }
public static Multimap<String, Object> getRandomDocument() { final StringBuilder s = new StringBuilder(); for (int i = 0; i < 3; i++) s.append(RandomGenerator.randomString(5, 8)).append(" "); Multimap values = HashMultimap.create(); values.put(TEXT, s.toString()); values.put(NAME, s.toString()); values.put(TIME, Math.abs(random.nextLong())); values.put(WEIGHT, random.nextDouble()); values.put(LOCATION, Geoshape.point(random.nextDouble() * 180 - 90, random.nextDouble() * 360 - 180)); return values; }
@Test public void encoding() { // long l = 82348278L; Random rand = new Random(666); for (int r = 0; r < 2000; r++) { long l = Math.abs(rand.nextLong()); String encoded = Utils.encode(l); // System.out.println("Encoded " + l + " to " + encoded); long decoded = Utils.decode(encoded); assertEquals(l, decoded); } }
/** * @throws Exception If failed. */ @Test public void testChar() throws Exception { char val = (char)RND.nextLong(); out.writeChar(val); assertEquals(val, getCharByByteLE(out.internalArray())); assertEquals(val, in.readChar()); }
@Override public void emitBatch(long batchId, TridentCollector collector) { List<List<Object>> values; if(batches.containsKey(batchId)) { values = batches.get(batchId); } else { values = new ArrayList<>(); for (int i = 0; i < batchSize; i++) { // tuple values are mapped with // metric, timestamp, value, Map of tagK/tagV respectively. values.add(Lists.newArrayList(Lists.newArrayList("device.temp", System.currentTimeMillis(), new Random().nextLong(), Collections.singletonMap("loc.id", new Random().nextInt() % 64 + "")))); } batches.put(batchId, values); } for (List<Object> value : values) { collector.emit(value); } }
@Test public void testRandomMultiplyDivideInverse() { final int N = 100000; final long MASK56 = 0x00FFFFFFFFFFFFL; // 56 bit mask to generate positive 56 bit longs // from random signed longs int seed = 897089790; Random rand = new Random(seed); long l1, l2; for (int i = 1; i <= N; i++) { l1 = rand.nextLong() & MASK56; l2 = rand.nextLong() & MASK56; verifyMultiplyDivideInverse(l1, l2); } }
/** Creates a new random number generator. This constructor sets the seed of the random number generator to a value very likely * to be distinct from any other invocation of this constructor. * <p> * This implementation creates a {@link Random} instance to generate the initial seed. */ public RandomXS128 () { setSeed(new Random().nextLong()); }
private static Object generateSingleValue(Random random, FieldSpec.DataType dataType) { switch (dataType) { case INT: return Math.abs(random.nextInt()); case LONG: return Math.abs(random.nextLong()); case FLOAT: return Math.abs(random.nextFloat()); case DOUBLE: return Math.abs(random.nextDouble()); case STRING: return RandomStringUtils.randomAlphabetic(DEFAULT_STRING_VALUE_LENGTH); default: throw new IllegalStateException("Illegal data type"); } }
public String generate(HttpServletRequest request) { String id = null; while (id == null || id.length() == 0) { //)||idInUse(id)) long r0 = weakRandom ? (hashCode()^Runtime.getRuntime().freeMemory()^random.nextInt()^(((long)request.hashCode())<<32)) : random.nextLong(); long r1 = random.nextLong(); if (r0<0) r0 = -r0; if (r1<0) r1 = -r1; id=Long.toString(r0,36)+Long.toString(r1,36); } return id; } }
@Override public Long nextValue() { long value = 0; Random random = ThreadLocalRandom.current(); if (random.nextDouble() < hotOpnFraction) { // Choose a value from the hot set. value = lowerBound + Math.abs(random.nextLong()) % hotInterval; } else { // Choose a value from the cold set. value = lowerBound + hotInterval + Math.abs(random.nextLong()) % coldInterval; } setLastValue(value); return value; }
@Test public void testSimpleTypesObjects() { SimpleTypes a = new SimpleTypes(); SimpleTypes b = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes c = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes d = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes e = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes f = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes g = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); runTests(a, b, c, d, e, f, g); }