当前位置: 首页>>代码示例>>Java>>正文


Java ThreadLocalRandom.current方法代码示例

本文整理汇总了Java中java.util.concurrent.ThreadLocalRandom.current方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadLocalRandom.current方法的具体用法?Java ThreadLocalRandom.current怎么用?Java ThreadLocalRandom.current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ThreadLocalRandom的用法示例。


在下文中一共展示了ThreadLocalRandom.current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRandomStringBasedOnTimestamp

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * 根据当前时间(hour)戳创建字符串,包括8位随机字符串和时间戳
 * 
 * @return
 * @throws UnsupportedEncodingException 
 */
public static String createRandomStringBasedOnTimestamp(int type) throws UnsupportedEncodingException{

    String timestampStr = createTimestampStr(type);
    
    
    Random random = ThreadLocalRandom.current();
    int p = random.nextInt(8-1);
    int length = 8+timestampStr.length();
    StringBuffer strBuffer = new StringBuffer(length);
    
    
    for(int i=0;i<length;i++){
        strBuffer.append(base[random.nextInt(base.length)]);
        if(i==p){
            strBuffer.append(timestampStr);
        }
    }
    return strBuffer.toString();
    
}
 
开发者ID:sylinklee,项目名称:netto_rpc,代码行数:27,代码来源:RandomStrGenerator.java

示例2: handleDiceRoll

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
private void handleDiceRoll(@NotNull MessageReceivedEvent event, @NotNull List<String> args) {
    int upper = Integer.parseUnsignedInt(args.get(0).substring(2));
    int iterations = 1;
    if (args.size() > 1 && INT_PATTERN.matcher(args.get(1)).find()) {
        iterations = Math.min(12, Integer.parseUnsignedInt(args.get(1)));
    }
    int sIterations = iterations;
    ThreadLocalRandom random = ThreadLocalRandom.current();
    EmbedBuilder builder = MessageUtils.getEmbedBuilder(event.getMessage().getAuthor());
    int sum = 0;
    while (iterations-- != 0) {
        int num = random.nextInt(1, upper + 1);
        sum += num;
        builder.appendField(":game_die: [1," + upper + "]", num + "", true);
    }
    builder.withTitle("Tossed " + sIterations + (sIterations == 1 ? " dice" : " dices"));
    builder.withDescription("Average result: " + (sum / sIterations));

    sendThenDelete(MessageUtils.getMessageBuilder(event.getMessage())
            .withEmbed(builder.build()));
    delete(event.getMessage());
}
 
开发者ID:ViniciusArnhold,项目名称:ProjectAltaria,代码行数:23,代码来源:RandomNumberCommand.java

示例3: newBuilderInstance

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
private static Builder newBuilderInstance() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    return new Builder(UUID.randomUUID().toString(),
            random.nextInt(),
            UUID.randomUUID().toString(),
            Instant.ofEpochMilli(random.nextLong(0, Instant.now().toEpochMilli())));
}
 
开发者ID:richardstartin,项目名称:simdbenchmarks,代码行数:8,代码来源:HashSetContainsBenchmark.java

示例4: testNextIntBadBounds

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * nextInt(least >= bound) throws IllegalArgumentException
 */
public void testNextIntBadBounds() {
    int[][] badBoundss = {
        { 17, 2 },
        { -42, -42 },
        { Integer.MAX_VALUE, Integer.MIN_VALUE },
    };
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    for (int[] badBounds : badBoundss) {
        try {
            rnd.nextInt(badBounds[0], badBounds[1]);
            shouldThrow();
        } catch (IllegalArgumentException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ThreadLocalRandomTest.java

示例5: testSortTaskDemo

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * SortTask demo works as advertised
 */
public void testSortTaskDemo() {
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    long[] array = new long[1007];
    for (int i = 0; i < array.length; i++)
        array[i] = rnd.nextLong();
    long[] arrayClone = array.clone();
    testInvokeOnPool(mainPool(), new SortTask(array));
    Arrays.sort(arrayClone);
    assertTrue(Arrays.equals(array, arrayClone));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:RecursiveActionTest.java

示例6: correctnessTesting

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
@Test
void correctnessTesting() throws Exception {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    for(int i = 0; i < 20; i++) {
        ZipfDistribution zipf = new ZipfDistribution(random.nextDouble(), 1000);

        long[] original = zipf.stream().limit(2000).asLongStream().toArray();
        verifyCompression(original, -1);
    }
}
 
开发者ID:burmanm,项目名称:compression-int,代码行数:11,代码来源:Simple8EncodeTest.java

示例7: spread

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
private void spread() {
    World world = GameState.getGameWorld();
    ThreadLocalRandom random = ThreadLocalRandom.current();
    int spreadSize = UHC.getInstance().getMainConfig().getWorldBorderInitialSize();
    Stream<? extends Player> players = Bukkit.getServer().getOnlinePlayers().stream().filter(player -> player.getGameMode() != GameMode.SPECTATOR);

    players.forEach(player -> player.teleport(generateSafe(spreadSize, world, random)));
}
 
开发者ID:Project-Coalesce,项目名称:UHC,代码行数:9,代码来源:GameInitializeHandler.java

示例8: testUnsizedDoublesCountSeq

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:ThreadLocalRandomTest.java

示例9: randomMetric

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
public static Metric randomMetric(int numMetrics, int numDimensions, int numLabels) {
  ThreadLocalRandom r = ThreadLocalRandom.current();
  int i = r.nextInt(0, numMetrics);
  int[] labs = new int[numDimensions];
  for (int j = 0; j < numDimensions; j++) {
    labs[j] = r.nextInt(0, numLabels);
  }
  return metric(i, labs);
}
 
开发者ID:pinterest,项目名称:yuvi,代码行数:10,代码来源:InvertedIndexTagStoreBenchmark.java

示例10: nextString

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * Generates a random string of a length with a range, inclusive on either end.
 * @param min   min length
 * @param max   max length
 * @return a random string whose length is with the provided boundaries (inclusive)
 */
public static String nextString(Integer min, Integer max) {
    int length = stringLength(adjustStringLength(min), adjustStringLength(max));

    StringBuilder sb = new StringBuilder(length);
    Random random = ThreadLocalRandom.current();
    for (int i = 0; i < length; i++) {
        sb.append(RAND_CHARS.charAt(random.nextInt(RAND_CHARS.length())));
    }
    return sb.toString();
}
 
开发者ID:zezutom,项目名称:schematic,代码行数:17,代码来源:RandomUtil.java

示例11: testLongsCount

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * A parallel sized stream of longs generates the given number of values
 */
public void testLongsCount() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 0;
    for (int reps = 0; reps < REPS; ++reps) {
        counter.reset();
        r.longs(size).parallel().forEach(x -> counter.increment());
        assertEquals(size, counter.sum());
        size += 524959;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ThreadLocalRandom8Test.java

示例12: setup

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
public void setup() {
    input = new GeoCoordTuple[size];
    ThreadLocalRandom random = ThreadLocalRandom.current();
    for (int i = 0; i < size; i++) {
        input[i] = new GeoCoordTuple(
                getLat(random),
                getLong(random),
                getLat(random),
                getLong(random)
        );
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:13,代码来源:DistanceCalcBenchmark.java

示例13: testUnsizedDoublesCountSeq

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * 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(size, counter.sum());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ThreadLocalRandom8Test.java

示例14: testUnsizedLongsCountSeq

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
/**
 * A sequential unsized stream of longs generates at least 100 values
 */
public void testUnsizedLongsCountSeq() {
    LongAdder counter = new LongAdder();
    ThreadLocalRandom r = ThreadLocalRandom.current();
    long size = 100;
    r.longs().limit(size).forEach(x -> counter.increment());
    assertEquals(size, counter.sum());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ThreadLocalRandom8Test.java

示例15: generator

import java.util.concurrent.ThreadLocalRandom; //导入方法依赖的package包/类
public static String generator(String dbName, String tblName, long beginTime, long endTime)
{
    ConsumerConfig config = ConsumerConfig.INSTANCE();
    String hdfsWarehouse = config.getHDFSWarehouse();
    ThreadLocalRandom tlr = ThreadLocalRandom.current();
    long random = tlr.nextLong();
    return String.format("%s/%s/%s/%s-%s-%d%d%d", hdfsWarehouse, dbName, tblName, dbName, tblName, beginTime, endTime, random);
}
 
开发者ID:dbiir,项目名称:paraflow,代码行数:9,代码来源:FileNameGenerator.java


注:本文中的java.util.concurrent.ThreadLocalRandom.current方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。