/** * Generates a random value from the {@link ZipfDistribution Zipf Distribution}. * * @param numberOfElements the number of elements of the ZipfDistribution * @param exponent the exponent of the ZipfDistribution * @return random value sampled from the Zipf(numberOfElements, exponent) distribution * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0} * or {@code exponent <= 0}. */ public int nextZipf(int numberOfElements, double exponent) throws NotStrictlyPositiveException { return new ZipfDistribution(getRandomGenerator(), numberOfElements, exponent).sample(); }
protected String prepareTestDate() throws IOException { String[] allKeys = new String[KEY_SPACE]; for (int i = 0; i < KEY_SPACE; i++) { allKeys[i] = RandomStringUtils.randomAlphabetic(10); } outputMsg("Start to create test random data..."); long startTime = System.currentTimeMillis(); ZipfDistribution zipf = new ZipfDistribution(KEY_SPACE, 0.5); int keyIndex; File tempFile = File.createTempFile("ZipfDistribution", ".txt"); if (tempFile.exists()) FileUtils.forceDelete(tempFile); Writer fw = new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8); try { for (int i = 0; i < TOTAL_RECORDS; i++) { keyIndex = zipf.sample() - 1; fw.write(allKeys[keyIndex]); fw.write('\n'); } } finally { if (fw != null) fw.close(); } outputMsg("Create test data takes : " + (System.currentTimeMillis() - startTime) / 1000 + " seconds."); outputMsg("Test data in : " + tempFile.getAbsolutePath()); return tempFile.getAbsolutePath(); }
private int getNextVal(int mult) { int rval; if (zipfian) { rval = zipf.sample(); } else { rval = (int) Math.abs(Math.floor(rng.nextDouble() * mult)); } return rval; }
@Override public String getNextKey() { int keyIndex = zipf.sample(); if (isPreLoadKeys()) { return keys.get(keyIndex); } else { return "T" + keyIndex; } } }
@Override public String getNextKey() { int keyIndex = zipf.sample(); if (isPreLoadKeys()) { return keys.get(keyIndex); } else { return "T" + keyIndex; } } }
/** * Generates a random value from the {@link ZipfDistribution Zipf Distribution}. * * @param numberOfElements the number of elements of the ZipfDistribution * @param exponent the exponent of the ZipfDistribution * @return random value sampled from the Zipf(numberOfElements, exponent) distribution * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0} * or {@code exponent <= 0}. */ public int nextZipf(int numberOfElements, double exponent) throws NotStrictlyPositiveException { return new ZipfDistribution(getRandomGenerator(), numberOfElements, exponent).sample(); }
/** * Generates a random value from the {@link ZipfDistribution Zipf Distribution}. * * @param numberOfElements the number of elements of the ZipfDistribution * @param exponent the exponent of the ZipfDistribution * @return random value sampled from the Zipf(numberOfElements, exponent) distribution * @exception NotStrictlyPositiveException if {@code numberOfElements <= 0} * or {@code exponent <= 0}. */ public int nextZipf(int numberOfElements, double exponent) throws NotStrictlyPositiveException { return new ZipfDistribution(getRandomGenerator(), numberOfElements, exponent).sample(); }