Example usage for org.apache.commons.math3.distribution ZipfDistribution sample

List of usage examples for org.apache.commons.math3.distribution ZipfDistribution sample

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution ZipfDistribution sample.

Prototype

public int sample() 

Source Link

Document

The default implementation uses the <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> inversion method</a>.

Usage

From source file:org.apache.accumulo.core.file.rfile.RolllingStatsTest.java

@Test
public void testZipf() {
    ZipfDistribution zd = new ZipfDistribution(new Well19937c(42), 1000, 2);
    testDistribrution(() -> zd.sample() * 100);
}

From source file:org.apache.kylin.measure.topn.TopNCounterTest.java

protected String prepareTestDate() throws IOException {
    String[] allKeys = new String[KEY_SPACE];

    for (int i = 0; i < KEY_SPACE; i++) {
        allKeys[i] = RandomStringUtils.randomAlphabetic(10);
    }//from w  ww  .  ja v a 2s.  com

    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);
    FileWriter fw = new FileWriter(tempFile);
    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();
}