本文整理了Java中java.util.Random.ints()
方法的一些代码示例,展示了Random.ints()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Random.ints()
方法的具体详情如下:
包路径:java.util.Random
类名称:Random
方法名:ints
暂无
代码示例来源:origin: neo4j/neo4j
public IntStream ints( long streamSize, int randomNumberOrigin, int randomNumberBound )
{
return random.ints( streamSize, randomNumberOrigin, randomNumberBound );
}
代码示例来源:origin: shekhargulati/99-problems
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());
}
代码示例来源:origin: stackoverflow.com
Random r = new Random();
int[] fiveRandomNumbers = r.ints(5, 0, 11).toArray();
int randomNumber = r.ints(1, 0, 11).findFirst().getAsInt();
代码示例来源:origin: stackoverflow.com
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));}
));
代码示例来源:origin: prestodb/presto
private static int[] generateIds(int count, int range)
{
return new Random().ints(count, 0, range).toArray();
}
代码示例来源:origin: stackoverflow.com
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();
}
}
代码示例来源:origin: goldmansachs/gs-collections
int[] randomSeeds = new Random(0x123456789ABCDL).ints().limit((long) this.mapSizeDividedBy64).toArray();
this.randomIntsForValues = new Random(0x123456789ABCDL).ints().limit((long) (this.mapSizeDividedBy64 * 64)).toArray();
代码示例来源:origin: shekhargulati/99-problems
@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));
}
代码示例来源:origin: goldmansachs/gs-collections
this.randomIntegersForMap = new Random(0x123456789ABCDL).ints().limit((long) (this.mapSizeDividedBy16000 * 64)).toArray();
代码示例来源:origin: ehcache/ehcache3
@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));
}
代码示例来源:origin: opentripplanner/OpenTripPlanner
int[] randomNumbers = random.ints().limit(10007).map(Math::abs).toArray();
int nextRandom = 0;
代码示例来源:origin: opentripplanner/OpenTripPlanner
int[] randomNumbers = random.ints().limit(10007).map(Math::abs).toArray();
int nextRandom = 0;
代码示例来源:origin: stackoverflow.com
int[] array = new Random().ints(limit, low, high).toArray();
代码示例来源:origin: stackoverflow.com
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(", ")));
代码示例来源:origin: stackoverflow.com
final int[] ints = new Random().ints(1, 50).distinct().limit(6).toArray();
代码示例来源:origin: palantir/atlasdb
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());
}
代码示例来源:origin: stackoverflow.com
new Random().ints(0, 50)
.parallel()
.distinct()
.limit(5)
.forEach(d -> System.out.println("s: " + d));
代码示例来源:origin: BruceEckel/OnJava8-Examples
public static void main(String[] args) {
new Random(47)
.ints(5, 20)
.distinct()
.limit(7)
.sorted()
.forEach(System.out::println);
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
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);
}
代码示例来源:origin: jenetics/jenetics
@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);
}
内容来源于网络,如有侵权,请联系作者删除!