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


Java SplittableRandom类代码示例

本文整理汇总了Java中java.util.SplittableRandom的典型用法代码示例。如果您正苦于以下问题:Java SplittableRandom类的具体用法?Java SplittableRandom怎么用?Java SplittableRandom使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: generateRandomString

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * Generates randomStr random string (for Multipart requests)
 * @param lenght the char number of the random string
 * @return the random string
 */
public static String generateRandomString(int lenght) {
    SplittableRandom splittableRandom = new SplittableRandom();
    StringBuffer randomStr = new StringBuffer();
    int randInt, temp;
    for (int i = 0; i < lenght; i++) {
        randInt = splittableRandom.nextInt(0, 2);
        if (randInt == 1) {
            temp = splittableRandom.nextInt('A', 'Z');
        } else {
            temp = splittableRandom.nextInt('a', 'z');
        }
        randomStr.append((char) temp);
    }
    return randomStr.toString();
}
 
开发者ID:rammarj,项目名称:burp-dynamic-js,代码行数:21,代码来源:Util.java

示例2: setSeed

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * {@inheritDoc} Applies only to the calling thread.
 */
@SuppressWarnings("contracts.postcondition.not.satisfied") @Override public void setSeed(
    final long seed) {
  if (this.seed == null) {
    super.setSeed(seed);
  }
  if (splittableRandoms != null) {
    splittableRandoms.set(new SplittableRandom(seed));
    if (entropyBits != null) {
      entropyBits.get().updateAndGet(oldValue -> Math.max(oldValue, SEED_LENGTH_BITS));
    }
    if (seeds != null) {
      seeds.set(BinaryUtils.convertLongToBytes(seed));
    }
  }
}
 
开发者ID:Pr0methean,项目名称:BetterRandom,代码行数:19,代码来源:SplittableRandomAdapter.java

示例3: generateRandomString

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * Generates a random string (for Multipart requests)
 * @param lenght the char number of the random string
 * @return the random string
 */
public static String generateRandomString(int lenght) {
    SplittableRandom splittableRandom = new SplittableRandom();
    StringBuffer a = new StringBuffer();
    int nextInt, temp;
    for (int i = 0; i < lenght; i++) {
        nextInt = splittableRandom.nextInt(0, 2);
        temp = 'a';
        if (nextInt == 1) {
            temp = splittableRandom.nextInt('A', 'Z');
        } else {
            temp = splittableRandom.nextInt('a', 'z');
        }
        a.append((char) temp);
    }
    return a.toString();
}
 
开发者ID:rammarj,项目名称:burp-reflected-param,代码行数:22,代码来源:Util.java

示例4: testNextIntBounded

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * nextInt(bound) returns 0 <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextIntBounded() {
    SplittableRandom sr = new SplittableRandom();
    // sample bound space across prime number increments
    for (int bound = 2; bound < MAX_INT_BOUND; bound += 524959) {
        int f = sr.nextInt(bound);
        assertTrue(0 <= f && f < bound);
        int i = 0;
        int j;
        while (i < NCALLS &&
               (j = sr.nextInt(bound)) == f) {
            assertTrue(0 <= j && j < bound);
            ++i;
        }
        assertTrue(i < NCALLS);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:SplittableRandomTest.java

示例5: testNextIntBounded2

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * nextInt(least, bound) returns least <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextIntBounded2() {
    SplittableRandom sr = new SplittableRandom();
    for (int least = -15485863; least < MAX_INT_BOUND; least += 524959) {
        for (int bound = least + 2; bound > least && bound < MAX_INT_BOUND; bound += 49979687) {
            int f = sr.nextInt(least, bound);
            assertTrue(least <= f && f < bound);
            int i = 0;
            int j;
            while (i < NCALLS &&
                   (j = sr.nextInt(least, bound)) == f) {
                assertTrue(least <= j && j < bound);
                ++i;
            }
            assertTrue(i < NCALLS);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:SplittableRandomTest.java

示例6: testNextLongBounded

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * nextLong(bound) returns 0 <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextLongBounded() {
    SplittableRandom sr = new SplittableRandom();
    for (long bound = 2; bound < MAX_LONG_BOUND; bound += 15485863) {
        long f = sr.nextLong(bound);
        assertTrue(0 <= f && f < bound);
        int i = 0;
        long j;
        while (i < NCALLS &&
               (j = sr.nextLong(bound)) == f) {
            assertTrue(0 <= j && j < bound);
            ++i;
        }
        assertTrue(i < NCALLS);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:SplittableRandomTest.java

示例7: testNextLongBounded2

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * nextLong(least, bound) returns least <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextLongBounded2() {
    SplittableRandom sr = new SplittableRandom();
    for (long least = -86028121; least < MAX_LONG_BOUND; least += 982451653L) {
        for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
            long f = sr.nextLong(least, bound);
            assertTrue(least <= f && f < bound);
            int i = 0;
            long j;
            while (i < NCALLS &&
                   (j = sr.nextLong(least, bound)) == f) {
                assertTrue(least <= j && j < bound);
                ++i;
            }
            assertTrue(i < NCALLS);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:SplittableRandomTest.java

示例8: testNextDoubleBounded2

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * nextDouble(least, bound) returns least <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextDoubleBounded2() {
    SplittableRandom sr = new SplittableRandom();
    for (double least = 0.0001; least < 1.0e20; least *= 8) {
        for (double bound = least * 1.001; bound < 1.0e20; bound *= 16) {
            double f = sr.nextDouble(least, bound);
            assertTrue(least <= f && f < bound);
            int i = 0;
            double j;
            while (i < NCALLS &&
                   (j = sr.nextDouble(least, bound)) == f) {
                assertTrue(least <= j && j < bound);
                ++i;
            }
            assertTrue(i < NCALLS);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:SplittableRandomTest.java

示例9: test

import java.util.SplittableRandom; //导入依赖的package包/类
static void test(int i, int nkeys, Class mapClass) throws Exception {
    System.out.print("Threads: " + i + "\t:");
    Map<Integer, Integer> map = (Map<Integer,Integer>)mapClass.newInstance();
    Integer[] key = makeKeys(nkeys);
    // Uncomment to start with a non-empty table
    //        for (int j = 0; j < nkeys; j += 4) // start 1/4 occupied
    //            map.put(key[j], key[j]);
    LoopHelpers.BarrierTimer timer = new LoopHelpers.BarrierTimer();
    CyclicBarrier barrier = new CyclicBarrier(i+1, timer);
    SplittableRandom rnd = new SplittableRandom();
    for (int t = 0; t < i; ++t)
        pool.execute(new Runner(map, key, barrier, rnd.split()));
    barrier.await();
    barrier.await();
    long time = timer.getTime();
    long tpo = time / (i * (long)nops);
    System.out.print(LoopHelpers.rightJustify(tpo) + " ns per op");
    double secs = (double)(time) / 1000000000.0;
    System.out.println("\t " + secs + "s run time");
    map.clear();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:MapLoops.java

示例10: testBoundedInts

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * Each of a parallel sized stream of bounded ints is within bounds
 */
public void testBoundedInts() {
    AtomicInteger fails = new AtomicInteger(0);
    SplittableRandom r = new SplittableRandom();
    long size = 12345L;
    for (int least = -15485867; least < MAX_INT_BOUND; least += 524959) {
        for (int bound = least + 2; bound > least && bound < MAX_INT_BOUND; bound += 67867967) {
            final int lo = least, hi = bound;
            r.ints(size, lo, hi).parallel().forEach(
                x -> {
                    if (x < lo || x >= hi)
                        fails.getAndIncrement(); });
        }
    }
    assertEquals(0, fails.get());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:SplittableRandomTest.java

示例11: testBoundedLongs

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * Each of a parallel sized stream of bounded longs is within bounds
 */
public void testBoundedLongs() {
    AtomicInteger fails = new AtomicInteger(0);
    SplittableRandom r = new SplittableRandom();
    long size = 123L;
    for (long least = -86028121; least < MAX_LONG_BOUND; least += 1982451653L) {
        for (long bound = least + 2; bound > least && bound < MAX_LONG_BOUND; bound += Math.abs(bound * 7919)) {
            final long lo = least, hi = bound;
            r.longs(size, lo, hi).parallel().forEach(
                x -> {
                    if (x < lo || x >= hi)
                        fails.getAndIncrement(); });
        }
    }
    assertEquals(0, fails.get());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:SplittableRandomTest.java

示例12: testBoundedDoubles

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * Each of a parallel sized stream of bounded doubles is within bounds
 */
public void testBoundedDoubles() {
    AtomicInteger fails = new AtomicInteger(0);
    SplittableRandom r = new SplittableRandom();
    long size = 456;
    for (double least = 0.00011; least < 1.0e20; least *= 9) {
        for (double bound = least * 1.0011; bound < 1.0e20; bound *= 17) {
            final double lo = least, hi = bound;
            r.doubles(size, lo, hi).parallel().forEach(
                x -> {
                    if (x < lo || x >= hi)
                        fails.getAndIncrement(); });
        }
    }
    assertEquals(0, fails.get());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:SplittableRandomTest.java

示例13: generateRandomString

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * Generates a random string (for Multipart requests)
 * @param lenght the char number of the random string
 * @return the random string
 */
public static String generateRandomString(int lenght) {
    SplittableRandom splittableRandom = new SplittableRandom();
    StringBuffer a = new StringBuffer();
    int nextInt, ext;
    for (int i = 0; i < lenght; i++) {
        nextInt = splittableRandom.nextInt(0, 2);
        ext = 'a';
        if (nextInt == 1) {
            ext = splittableRandom.nextInt('A', 'Z');
        } else {
            ext = splittableRandom.nextInt('a', 'z');
        }
        a.append((char) ext);
    }
    return a.toString();
}
 
开发者ID:rammarj,项目名称:csrf-poc-creator,代码行数:22,代码来源:Util.java

示例14: randomize

import java.util.SplittableRandom; //导入依赖的package包/类
/**
 * Randomizes the alive state of the cells.
 */
public void randomize() {
    SplittableRandom random = new SplittableRandom();
    int rows = getRows();
    int columns = getColumns();
    boolean[][] aliveMatrix = new boolean[rows][columns];

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            aliveMatrix[i][j] = random.nextInt() >= 0;
        }
    }

    board.setAliveMatrix(aliveMatrix);

    draw();
}
 
开发者ID:rubengees,项目名称:ConvaysGameOfLife,代码行数:20,代码来源:MainController.java

示例15: nextBytes

import java.util.SplittableRandom; //导入依赖的package包/类
/** Delegates to {@link SplittableRandom#nextInt(int) SplittableRandom.nextInt(256)}. */
@SuppressWarnings("NumericCastThatLosesPrecision") @Override public void nextBytes(
    final byte[] bytes) {
  final SplittableRandom local = getSplittableRandom();
  for (int i = 0; i < bytes.length; i++) {
    bytes[i] = (byte) (local.nextInt(256));
  }
  debitEntropy(bytes.length * (long) (Byte.SIZE));
}
 
开发者ID:Pr0methean,项目名称:BetterRandom,代码行数:10,代码来源:BaseSplittableRandomAdapter.java


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