java.util.Random.longs()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中java.util.Random.longs()方法的一些代码示例,展示了Random.longs()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Random.longs()方法的具体详情如下:
包路径:java.util.Random
类名称:Random
方法名:longs

Random.longs介绍

暂无

代码示例

代码示例来源:origin: goldmansachs/gs-collections

long[] randomLongsGet = new Random(0x123456789ABCDL).longs().limit(this.mapSizeDividedBy16000).toArray();

代码示例来源:origin: ben-manes/caffeine

@Test(dataProvider = "filterTypes")
public void bloomFilterTest(FilterType filterType) {
 for (int capacity = 2 << 10; capacity < (2 << 22); capacity = capacity << 2) {
  long[] input = new Random().longs(capacity).distinct().toArray();
  List<String[]> rows = new ArrayList<>();
  int expectedInsertions = capacity / 2;
  Membership filter = filterType.create(expectedInsertions, FPP, CONFIG);
  int falsePositives = falsePositives(filter, input);
  double falsePositiveRate = ((double) falsePositives / expectedInsertions);
  assertThat(filterType.toString(), falsePositiveRate, is(lessThan(FPP + 0.01)));
  rows.add(row(filterType, expectedInsertions, falsePositives, falsePositiveRate));
  if (display) {
   printTable(rows);
  }
 }
}

代码示例来源:origin: ehcache/ehcache3

@Test(timeout=180000)
public void testCRUD() throws Exception {
 Random random = new Random();
 LongStream longStream = random.longs(1000);
 Set<Long> added = new HashSet<>();
 longStream.forEach(x -> {
  CACHE1.put(x, new BlobValue());
  added.add(x);
 });
 Set<Long> readKeysByCache2BeforeFailOver = new HashSet<>();
 added.forEach(x -> {
  if (CACHE2.get(x) != null) {
   readKeysByCache2BeforeFailOver.add(x);
  }
 });
 CLUSTER.getClusterControl().terminateActive();
 Set<Long> readKeysByCache1AfterFailOver = new HashSet<>();
 added.forEach(x -> {
  if (CACHE1.get(x) != null) {
   readKeysByCache1AfterFailOver.add(x);
  }
 });
 assertThat(readKeysByCache2BeforeFailOver.size(), greaterThanOrEqualTo(readKeysByCache1AfterFailOver.size()));
 readKeysByCache1AfterFailOver.stream().filter(readKeysByCache2BeforeFailOver::contains).forEach(y -> assertThat(CACHE2.get(y), notNullValue()));
}

代码示例来源:origin: ehcache/ehcache3

@Test(timeout=180000)
@Ignore //TODO: FIXME: FIX THIS RANDOMLY FAILING TEST
public void testBulkOps() throws Exception {
 List<Cache<Long, BlobValue>> caches = new ArrayList<>();
 caches.add(CACHE1);
 caches.add(CACHE2);
 Map<Long, BlobValue> entriesMap = new HashMap<>();
 Random random = new Random();
 LongStream longStream = random.longs(1000);
 longStream.forEach(x -> entriesMap.put(x, new BlobValue()));
 caches.forEach(cache -> cache.putAll(entriesMap));
 Set<Long> keySet = entriesMap.keySet();
 Set<Long> readKeysByCache2BeforeFailOver = new HashSet<>();
 keySet.forEach(x -> {
  if (CACHE2.get(x) != null) {
   readKeysByCache2BeforeFailOver.add(x);
  }
 });
 CLUSTER.getClusterControl().terminateActive();
 Set<Long> readKeysByCache1AfterFailOver = new HashSet<>();
 keySet.forEach(x -> {
  if (CACHE1.get(x) != null) {
   readKeysByCache1AfterFailOver.add(x);
  }
 });
 assertThat(readKeysByCache2BeforeFailOver.size(), greaterThanOrEqualTo(readKeysByCache1AfterFailOver.size()));
 readKeysByCache1AfterFailOver.stream().filter(readKeysByCache2BeforeFailOver::contains).forEach(y -> assertThat(CACHE2.get(y), notNullValue()));
}

代码示例来源:origin: ehcache/ehcache3

@Test(timeout=180000)
public void testClear() throws Exception {
 List<Cache<Long, BlobValue>> caches = new ArrayList<>();
 caches.add(CACHE1);
 caches.add(CACHE2);
 Map<Long, BlobValue> entriesMap = new HashMap<>();
 Random random = new Random();
 LongStream longStream = random.longs(1000);
 longStream.forEach(x -> entriesMap.put(x, new BlobValue()));
 caches.forEach(cache -> cache.putAll(entriesMap));
 Set<Long> keySet = entriesMap.keySet();
 Set<Long> readKeysByCache2BeforeFailOver = new HashSet<>();
 keySet.forEach(x -> {
  if (CACHE2.get(x) != null) {
   readKeysByCache2BeforeFailOver.add(x);
  }
 });
 CACHE1.clear();
 CLUSTER.getClusterControl().terminateActive();
 if (cacheConsistency == Consistency.STRONG) {
  readKeysByCache2BeforeFailOver.forEach(x -> assertThat(CACHE2.get(x), nullValue()));
 } else {
  readKeysByCache2BeforeFailOver.forEach(x -> assertThat(CACHE1.get(x), nullValue()));
 }
}

代码示例来源:origin: prestodb/presto

@Test
public void testLazyBlockBuilderInitialization()
{
  long[][] expectedValues = new long[ARRAY_SIZES.length][];
  Random rand = new Random(47);
  for (int i = 0; i < ARRAY_SIZES.length; i++) {
    expectedValues[i] = rand.longs(ARRAY_SIZES[i]).toArray();
  }
  BlockBuilder emptyBlockBuilder = new ArrayBlockBuilder(BIGINT, null, 0, 0);
  BlockBuilder blockBuilder = new ArrayBlockBuilder(BIGINT, null, 100, 100);
  assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes());
  assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes());
  writeValues(expectedValues, blockBuilder);
  assertTrue(blockBuilder.getSizeInBytes() > emptyBlockBuilder.getSizeInBytes());
  assertTrue(blockBuilder.getRetainedSizeInBytes() > emptyBlockBuilder.getRetainedSizeInBytes());
  blockBuilder = blockBuilder.newBlockBuilderLike(null);
  assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes());
  assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes());
}

代码示例来源:origin: prestodb/presto

@Test
public void testWithFixedWidthBlock()
{
  long[][] expectedValues = new long[ARRAY_SIZES.length][];
  Random rand = new Random(47);
  for (int i = 0; i < ARRAY_SIZES.length; i++) {
    expectedValues[i] = rand.longs(ARRAY_SIZES[i]).toArray();
  }
  BlockBuilder blockBuilder = createBlockBuilderWithValues(expectedValues);
  assertBlock(blockBuilder, () -> blockBuilder.newBlockBuilderLike(null), expectedValues);
  assertBlock(blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), expectedValues);
  assertBlockFilteredPositions(expectedValues, blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), 0, 1, 3, 4, 7);
  assertBlockFilteredPositions(expectedValues, blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), 2, 3, 5, 6);
  long[][] expectedValuesWithNull = alternatingNullValues(expectedValues);
  BlockBuilder blockBuilderWithNull = createBlockBuilderWithValues(expectedValuesWithNull);
  assertBlock(blockBuilderWithNull, () -> blockBuilder.newBlockBuilderLike(null), expectedValuesWithNull);
  assertBlock(blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), expectedValuesWithNull);
  assertBlockFilteredPositions(expectedValuesWithNull, blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), 0, 1, 5, 6, 7, 10, 11, 12, 15);
  assertBlockFilteredPositions(expectedValuesWithNull, blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), 2, 3, 4, 9, 13, 14);
}

代码示例来源:origin: bazaarvoice/emodb

RandomExpirationSupplier(Supplier<T> delegate, long minDuration, long maxDuration, TimeUnit timeUnit) {
  checkArgument(minDuration >= 0, "minDuration cannot be negative");
  checkArgument(maxDuration > minDuration, "maxDuration must be greater than minDuration");
  checkNotNull(delegate, "delegate");
  checkNotNull(timeUnit, "timeUnit");
  long minDurationNanos = timeUnit.toNanos(minDuration);
  long maxDurationNanos = timeUnit.toNanos(maxDuration);
  _delegate = delegate;
  _nanosDurations = new Random().longs(minDurationNanos, maxDurationNanos).iterator();
}

代码示例来源:origin: FINRAOS/DataGenerator

public Stream<Long> longStream(Long size, Long start, Long bound) {
    return random.longs(size, start, bound).boxed();
  }
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-common-dropwizard

RandomExpirationSupplier(Supplier<T> delegate, long minDuration, long maxDuration, TimeUnit timeUnit) {
  checkArgument(minDuration >= 0, "minDuration cannot be negative");
  checkArgument(maxDuration > minDuration, "maxDuration must be greater than minDuration");
  checkNotNull(delegate, "delegate");
  checkNotNull(timeUnit, "timeUnit");
  long minDurationNanos = timeUnit.toNanos(minDuration);
  long maxDurationNanos = timeUnit.toNanos(maxDuration);
  _delegate = delegate;
  _nanosDurations = new Random().longs(minDurationNanos, maxDurationNanos).iterator();
}

代码示例来源:origin: smartcat-labs/ranger

@Override
public long nextLong(long bound) {
  return random.longs(1, 0, bound).findFirst().getAsLong();
}

代码示例来源:origin: io.smartcat/ranger

@Override
public long nextLong(long lower, long upper) {
  return random.longs(1, lower, upper).findFirst().getAsLong();
}

代码示例来源:origin: io.smartcat/ranger

@Override
public long nextLong(long bound) {
  return random.longs(1, 0, bound).findFirst().getAsLong();
}

代码示例来源:origin: stackoverflow.com

public Optional<QuoteOfTheDay> random() {
  long count = repository.count();
  if(count==0) return Optional.empty();
  Random r = new Random();
  long randomIndex=count<=Integer.MAX_VALUE? r.nextInt((int)count):
    r.longs(1, 0, count).findFirst().orElseThrow(AssertionError::new);
  return StreamSupport.stream(repository.findAll().spliterator(), false)
    .skip(randomIndex).findFirst();
}

代码示例来源:origin: com.tyro.oss/random-data

public static long randomLongBetween(long startInclusive, long endInclusive) {
  return RANDOM.longs(startInclusive, addExact(endInclusive, 1))
      .findFirst()
      .getAsLong();
}

代码示例来源:origin: stackoverflow.com

public List<Point> getRandomPoints(int num) {
  long count=allValues().count();

  assert count > num;

  return new Random().longs(0, count)
    .distinct()
    .limit(num)
    .mapToObj(i -> allValues().skip(i).findFirst().get())
    .collect(Collectors.toList());
}

代码示例来源:origin: spotify/spydra

static ClusterPlacement createClusterPlacement(
  Supplier<Long> timeSource,
  int clusterNumber,
  SpydraArgument.Pooling pooling) {
 long time = timeSource.get() / 1000;
 long age = pooling.getMaxAge().getSeconds();
 long timeOffset = new Random(clusterNumber).longs(1, 0, age).findFirst().getAsLong();
 long generation = computeGeneration(time + timeOffset, age);
 return new ClusterPlacementBuilder()
   .clusterNumber(clusterNumber)
   .clusterGeneration(generation)
   .build();
}

代码示例来源:origin: jenetics/jenetics

@Test(dataProvider = "sorters")
public void sortRandomLongValues(final IndexSorter sorter, final Integer size) {
  final long[] values = new Random().longs(size).toArray();
  final long[] actual = indexSort(sorter, values);
  final long[] expected = arraySort(values);
  Assert.assertEquals(actual, expected);
}

代码示例来源:origin: Nike-Inc/riposte

private Set<Cookie> createCookies(int numberOfCookies) {
  if (numberOfCookies < 0) {
    return null;
  }
  Set<Cookie> cookies = new HashSet<>();
  for (int x = 0; x < numberOfCookies; x++) {
    Cookie cookie = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    cookie.setHttpOnly(new Random().ints(0, 1000).findAny().getAsInt() % 2 == 0);
    cookie.setMaxAge(new Random().longs(0, 1000).findAny().getAsLong());
    cookies.add(cookie);
  }
  return cookies;
}

代码示例来源:origin: osmlab/atlas

private Location[] getTwoNodes(final PackedAtlas packedAtlas, final long size)
  {
    final OfLong iterator = this.random.longs(0, size).iterator();
    final long index1 = iterator.next();
    final long index2 = iterator.next();
    final Location[] result = new Location[2];
    result[0] = packedAtlas.nodeLocation(index1);
    result[1] = packedAtlas.nodeLocation(index2);
    return result;
  }
}

相关文章