use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
the class ThreadLocalRandomTest method testUnsizedDoublesCountSeq.
/**
* A sequential unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.doubles().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
the class ThreadLocalRandomTest method testUnsizedIntsCount.
/**
* A parallel unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.ints().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java.util.concurrent.ThreadLocalRandom in project jdk8u_jdk by JetBrains.
the class ThreadLocalRandomTest method testUnsizedDoublesCount.
/**
* A parallel unsized stream of doubles generates at least 100 values
*/
public void testUnsizedDoublesCount() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.doubles().limit(size).parallel().forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java.util.concurrent.ThreadLocalRandom in project gerrit by GerritCodeReview.
the class SmtpEmailSender method generateMultipartBoundary.
public static String generateMultipartBoundary(String textBody, String htmlBody) throws EmailException {
byte[] bytes = new byte[8];
ThreadLocalRandom rng = ThreadLocalRandom.current();
// suffice, something is seriously wrong.
for (int i = 0; i < 2; i++) {
rng.nextBytes(bytes);
String boundary = BaseEncoding.base64().encode(bytes);
String encBoundary = "--" + boundary;
if (textBody.contains(encBoundary) || htmlBody.contains(encBoundary)) {
continue;
}
return boundary;
}
throw new EmailException("Gave up generating unique MIME boundary");
}
use of java.util.concurrent.ThreadLocalRandom in project Glowstone by GlowstoneMC.
the class BlockOre method getDrops.
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
ThreadLocalRandom random = ThreadLocalRandom.current();
int count = minCount;
if (maxCount > minCount) {
count += random.nextInt(maxCount - minCount);
}
ItemStack stack = new ItemStack(dropType, count, (short) data);
if (tool == null) {
return Collections.unmodifiableList(Arrays.asList(stack));
}
Collection<ItemStack> drops = super.getDrops(block, tool);
if (drops.size() == 0) {
return drops;
}
if (tool.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) {
stack.setAmount(count * getMultiplicator(random, tool.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS)));
}
return Collections.unmodifiableList(Arrays.asList(stack));
}
Aggregations