本文整理了Java中java.util.Random.nextLong()
方法的一些代码示例,展示了Random.nextLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Random.nextLong()
方法的具体详情如下:
包路径:java.util.Random
类名称:Random
方法名:nextLong
[英]Returns a pseudo-random uniformly distributed long.
[中]
代码示例来源:origin: libgdx/libgdx
/** 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());
}
代码示例来源:origin: jfinal/jfinal
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;
}
}
代码示例来源:origin: apache/storm
@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 + "")));
}
}
代码示例来源:origin: apache/hbase
@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);
}
代码示例来源:origin: apache/ignite
/**
* @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());
}
代码示例来源:origin: apache/hive
@Test
public void testRandomAddSubtractInverse() {
final int N = 1000000;
int seed = 1427480960;
Random rand = new Random(seed);
long l1, l2;
for (int i = 1; i <= N; i++) {
l1 = rand.nextLong();
l2 = rand.nextLong();
verifyAddSubtractInverse(l1, l2);
}
}
代码示例来源:origin: apache/avro
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();
}
}
代码示例来源:origin: apache/flink
@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;
}
代码示例来源:origin: SonarSource/sonarqube
@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();
}
代码示例来源:origin: google/guava
private static void assertHashLongEquivalence(HashFunction hashFunction, Random random) {
long l = random.nextLong();
assertEquals(hashFunction.hashLong(l), hashFunction.newHasher().putLong(l).hash());
}
代码示例来源:origin: thinkaurelius/titan
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;
}
代码示例来源:origin: spring-projects/spring-loaded
@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);
}
}
代码示例来源:origin: apache/ignite
/**
* @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());
}
代码示例来源:origin: apache/storm
@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);
}
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: libgdx/libgdx
/** 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());
}
代码示例来源:origin: apache/incubator-pinot
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");
}
}
代码示例来源:origin: jfinal/jfinal
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;
}
}
代码示例来源:origin: brianfrankcooper/YCSB
@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;
}
代码示例来源:origin: apache/flink
@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);
}
内容来源于网络,如有侵权,请联系作者删除!