public IntStream ints( long streamSize, int randomNumberOrigin, int randomNumberBound ) { return random.ints( streamSize, randomNumberOrigin, randomNumberBound ); }
public static <T> List<T> randomSelect(List<T> list, int n) { return new Random().ints(n, 0, list.size()).mapToObj(list::get).collect(Collectors.toList()); }
new Random().ints(20, 0, 2).mapToObj(i -> (Either<String,Integer>)(i==0? Either.left("left value (String)"): Either.right(42))) .forEach(either->either.apply( left ->{ System.out.println("received left value: "+left.substring(11));}, right->{ System.out.println("received right value: 0x"+Integer.toHexString(right));} ));
private static int[] generateIds(int count, int range) { return new Random().ints(count, 0, range).toArray(); }
public final class RandomNumberGenerator { private PrimitiveIterator.OfInt randomIterator; /** * Initialize a new random number generator that generates * random numbers in the range [min, max] * @param min - the min value (inclusive) * @param max - the max value (inclusive) */ public RandomNumberGenerator(int min, int max) { randomIterator = new Random().ints(min, max + 1).iterator(); } /** * Returns a random number in the range (min, max) * @return a random number in the range (min, max) */ public int nextInt() { return randomIterator.nextInt(); } }
@Test public void shouldWorkOnARandomArray() throws Exception { int[] numbers = new Random().ints(100000, 1, 100000).toArray(); long start = System.currentTimeMillis(); int[] pairs = Problem01.twoSum(numbers, 100); long end = System.currentTimeMillis(); System.out.println(String.format("Total time taken %d sec(s)", (end - start) / 1000)); System.out.println(Arrays.toString(pairs)); assertThat(pairs.length, equalTo(2)); }
this.randomIntegersForMap = new Random(0x123456789ABCDL).ints().limit((long) (this.mapSizeDividedBy16000 * 64)).toArray();
@Test public void testLoadExistingRecoversInflightInvalidationsForEventualCache() throws Exception { ClusterTierActiveEntity activeEntity = new ClusterTierActiveEntity(defaultRegistry, defaultConfiguration, DEFAULT_MAPPER); EhcacheStateServiceImpl ehcacheStateService = defaultRegistry.getStoreManagerService(); ehcacheStateService.createStore(defaultStoreName, defaultStoreConfiguration, false); //Passive would have done this before failover InvalidationTracker invalidationTracker = ehcacheStateService.getInvalidationTracker(defaultStoreName); Random random = new Random(); random.ints(0, 100).limit(10).forEach(invalidationTracker::trackHashInvalidation); activeEntity.loadExisting(); assertThat(activeEntity.getInflightInvalidations().isEmpty(), is(false)); }
int[] randomNumbers = random.ints().limit(10007).map(Math::abs).toArray(); int nextRandom = 0;
int[] randomNumbers = random.ints().limit(10007).map(Math::abs).toArray(); int nextRandom = 0;
int[] array = new Random().ints(limit, low, high).toArray();
List<Integer> l=new Random().ints(100, 0, 1000).boxed().collect(Collectors.toList()); System.out.println(l); System.out.println(quickSort(l::stream) .map(Object::toString).collect(Collectors.joining(", ")));
final int[] ints = new Random().ints(1, 50).distinct().limit(6).toArray();
public Set<Cell> getCellsRequest(int numberOfCellsToRequest) { Preconditions.checkState(getNumRows() >= numberOfCellsToRequest, "Unable to request %s rows from a table that only has %s rows.", numberOfCellsToRequest, getNumRows()); return getRandom() .ints(0, getNumRows()) .distinct() .limit(numberOfCellsToRequest) .mapToObj(ConsecutiveNarrowTable::cell) .collect(Collectors.toSet()); }
new Random().ints(0, 50) .parallel() .distinct() .limit(5) .forEach(d -> System.out.println("s: " + d));
public static void main(String[] args) { new Random(47) .ints(5, 20) .distinct() .limit(7) .sorted() .forEach(System.out::println); } }
private String randomLetters(final int length) { return random.ints((int)'a', (int)'z' + 1) .limit(length) .mapToObj(a -> String.valueOf((char)a)) .reduce((a, b) -> a + b) .orElseThrow(IllegalStateException::new); }
@Test(dataProvider = "sorters") public void sortRandomSeqValues(final IndexSorter sorter, final Integer size) { final Integer[] values = new Random().ints(size).boxed().toArray(Integer[]::new); final Seq<Integer> actual = indexSort(sorter, ISeq.of(values)); final Integer[] expected = arraySort(values); Assert.assertEquals(actual.toArray(new Integer[0]), expected); }