public A test() { Random random = new Random(); int a2 = random.nextInt(); int a3 = a2 + 3; return new A(this, a2, a3, 4, 5, random.nextDouble()) { @Override public void m() { System.out.println(1); } }; }
/** 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()); }
/** * Randomly determine whether this call should result in a network failure in accordance with * configured behavior. When true, {@link #failureException()} should be thrown. */ public boolean calculateIsFailure() { return random.nextInt(100) < failurePercent; }
@Override void performAction(Random random, Iterable<? extends PrimitiveSink> sinks) { byte[] value = new byte[random.nextInt(128)]; random.nextBytes(value); int off = random.nextInt(value.length + 1); int len = random.nextInt(value.length - off + 1); for (PrimitiveSink sink : sinks) { sink.putBytes(value, off, len); } } },
public AlternativeJdkIdGenerator() { SecureRandom secureRandom = new SecureRandom(); byte[] seed = new byte[8]; secureRandom.nextBytes(seed); this.random = new Random(new BigInteger(seed).longValue()); }
/** * Generates a number in [0, 2^numBits) with an exponential distribution. The floor of the log2 of * the absolute value of the result is chosen uniformly at random in [0, numBits), and then the * result is chosen from those possibilities uniformly at random. * * <p>Zero is treated as having log2 == 0. */ static double randomDouble(int maxExponent) { double result = RANDOM_SOURCE.nextDouble(); result = Math.scalb(result, RANDOM_SOURCE.nextInt(maxExponent + 1)); return RANDOM_SOURCE.nextBoolean() ? result : -result; }
public void testByteArrayRoundTrips() { Random r = new Random(5); byte[] b = new byte[Longs.BYTES]; for (int i = 0; i < 1000; i++) { long num = r.nextLong(); assertEquals(num, Longs.fromByteArray(Longs.toByteArray(num))); r.nextBytes(b); long value = Longs.fromByteArray(b); assertTrue("" + value, Arrays.equals(b, Longs.toByteArray(value))); } }
private static ImmutableList<Double> generatePseudorandomDataset() { Random random = new Random(2211275185798966364L); ImmutableList.Builder<Double> largeDatasetBuilder = ImmutableList.builder(); for (int i = 0; i < PSEUDORANDOM_DATASET_SIZE; i++) { largeDatasetBuilder.add(random.nextGaussian()); } return largeDatasetBuilder.build(); }
@Override protected final void setUp() throws Exception { boolean fair = new Random().nextBoolean(); monitor = new Monitor(fair); tearDownStack.addTearDown(thread1 = new TestThread<>(monitor, "TestThread #1")); tearDownStack.addTearDown(thread2 = new TestThread<>(monitor, "TestThread #2")); }
/** Returns a random number between start (inclusive) and end (inclusive). */ static public long random (long start, long end) { return start + (long)(random.nextDouble() * (end - start)); }
/** {@inheritDoc} */ protected Long createRandomPk() { return random.nextLong(); }
@Override public UUID generateId() { byte[] randomBytes = new byte[16]; this.random.nextBytes(randomBytes); long mostSigBits = 0; for (int i = 0; i < 8; i++) { mostSigBits = (mostSigBits << 8) | (randomBytes[i] & 0xff); } long leastSigBits = 0; for (int i = 8; i < 16; i++) { leastSigBits = (leastSigBits << 8) | (randomBytes[i] & 0xff); } return new UUID(mostSigBits, leastSigBits); }
/** * Randomly determine whether this call should result in an HTTP error in accordance with * configured behavior. When true, {@link #createErrorResponse()} should be returned. */ public boolean calculateIsError() { return random.nextInt(100) < errorPercent; }
public void testCorrectOrdering_mediumHeapsPollFirst() { for (int attempts = 0; attempts < reduceIterationsIfGwt(5000); attempts++) { int size = new Random().nextInt(256) + 16; ArrayList<Integer> elements = createOrderedList(size); List<Integer> expected = ImmutableList.copyOf(elements); MinMaxPriorityQueue<Integer> q = MinMaxPriorityQueue.create(); long seed = insertRandomly(elements, q); while (!q.isEmpty()) { elements.add(q.pollFirst()); } assertEqualsUsingSeed(seed, expected, elements); } }
private Write getOffsetBufferWrite(Random random) { int dataSize = random.nextInt(MAX_BYTES_PER_WRITE * 2); byte[] data = new byte[dataSize]; int length = dataSize == 0 ? 0 : random.nextInt(dataSize); int offset = dataSize - length <= 0 ? 0 : random.nextInt(dataSize - length); random.nextBytes(data); return new Write(data, length, offset, WriteType.OFFSET_BUFFER); }
/** * Uses {@code request} to connect a new web socket. */ @Override public WebSocket newWebSocket(Request request, WebSocketListener listener) { RealWebSocket webSocket = new RealWebSocket(request, listener, new Random(), pingInterval); webSocket.connect(this); return webSocket; }