Example usage for org.apache.commons.math3.random RandomDataGenerator RandomDataGenerator

List of usage examples for org.apache.commons.math3.random RandomDataGenerator RandomDataGenerator

Introduction

In this page you can find the example usage for org.apache.commons.math3.random RandomDataGenerator RandomDataGenerator.

Prototype

public RandomDataGenerator() 

Source Link

Document

Construct a RandomDataGenerator, using a default random generator as the source of randomness.

Usage

From source file:RandomGenTest.java

public static void main(String[] args) {
    RandomDataGenerator rand = new RandomDataGenerator();

    Map<Object, Integer> map = new HashMap();
    for (int i = 0; i < 101; i++)
        map.put(i, 0);/*from   ww w . ja v a  2 s.  c  o m*/

    Map<Object, Integer> user = new HashMap();
    for (int i = 0; i < 100; i++) {
        int age = rand.nextInt(0, 100);
        /*int age = (int) rand.nextGaussian(50, 10D);
        if ((age > 100) || (age < 0)) {
           age = rand.nextInt(0, 100);
        }*/
        user.put(i, age);
    }

    for (int i = 0; i < 100000; i++) {
        //int age = rand.nextInt(0, 100);
        /*int age = (int) rand.nextGaussian(50, 10D);
        if ((age > 100) || (age < 0)) {
           age = rand.nextInt(0, 100);
        }*/

        //Seq
        //map.put(user.get(i%100), map.get(user.get(i%100))+1);

        //Rand
        int j = rand.nextInt(0, 99);
        map.put(user.get(j), map.get(user.get(j)) + 1);
    }

    display(map);
}

From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.RandomListGenerator.java

/**
 * @param args//w  w w .  j a va2s .c om
 */
public static void main(String[] args) {
    System.out.println("Have started list generator.");
    File outFile = new File("/tmp/randomList.txt");

    RandomDataGenerator generator = new RandomDataGenerator();

    int listSize = 503; // The size of the array / list to be generated

    // The Strings to be randomized
    String[] strings = { "0DE968C9-7309-C481-58F7-AB6CDB1011EF", "5C1D9939-136A-55DE-FD0E-61D8204E17C9",
            "B936DA83-8A45-E9F0-2EAE-D75F5C232E78" };

    try {

        for (int j = 0; j < listSize; j++) {
            FileUtils.write(outFile, strings[generator.nextInt(0, strings.length - 1)] + "\n", true); // Append to file                              
        }

    } catch (IOException e) {
        System.err.println("IOException in main.");
        e.printStackTrace();
    }

    System.out.println("Have finished list generator.");
}

From source file:ke.co.tawi.babblesms.server.utils.randomgenerate.IncomingLogGenerator.java

/**
 * @param args/*from  w ww.  jav  a  2s . c  om*/
 */
public static void main(String[] args) {
    System.out.println("Have started IncomingSMSGenerator.");
    File outFile = new File("/tmp/logs/incomingSMS.csv");
    RandomDataGenerator randomDataImpl = new RandomDataGenerator();

    String randomStrFile = "/tmp/random.txt";

    List<String> randomStrings = new ArrayList<>();
    int randStrLength = 0;

    long startDate = 1412380800; // Unix time in seconds for Oct 4 2014
    long stopDate = 1420070340; // Unix time for in seconds Dec 31 2014

    SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 2011-06-01 00:16:45" 

    List<String> shortcodeUuids = new ArrayList<>();
    shortcodeUuids.add("094def52-bc18-4a9e-9b84-c34cc6476c75");
    shortcodeUuids.add("e9570c5d-0cc4-41e5-81df-b0674e9dda1e");
    shortcodeUuids.add("a118c8ea-f831-4288-986d-35e22c91fc4d");
    shortcodeUuids.add("a2688d72-291b-470c-8926-31a903f5ed0c");
    shortcodeUuids.add("9bef62f6-e682-4efd-98e9-ca41fa4ef993");

    int shortcodeCount = shortcodeUuids.size() - 1;

    try {
        randomStrings = FileUtils.readLines(new File(randomStrFile));
        randStrLength = randomStrings.size();

        for (int j = 0; j < 30000; j++) {
            FileUtils.write(outFile,
                    // shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"   // Destination 
                    UUID.randomUUID().toString() + "|" // Unique Code
                            + randomDataImpl.nextLong(new Long("254700000000").longValue(),
                                    new Long("254734999999").longValue())
                            + "|" // Origin
                            + shortcodeUuids.get(randomDataImpl.nextInt(0, shortcodeCount)) + "|"
                            + randomStrings.get(randomDataImpl.nextInt(0, randStrLength - 1)) + "|" // Message
                            + "N|" // deleted
                            + dateFormatter.format(
                                    new Date(randomDataImpl.nextLong(startDate, stopDate) * 1000))
                            + "\n", // smsTime                  
                    true); // Append to file                              
        }

    } catch (IOException e) {
        System.err.println("IOException in main.");
        e.printStackTrace();
    }

    System.out.println("Have finished IncomingSMSGenerator.");
}

From source file:main.java.entry.Main.java

public static void main(String[] args) throws IOException {
    Global.rand = new Random();
    Global.rdg = new RandomDataGenerator();

    Global.LOGGER.info("Simulating shared-nothing OLTP database cluster.");

    ReadConfig.readArgs(args);/*w w  w  .j  av a 2  s .  c  o m*/

    // Reading simulation aspects
    ReadConfig.readConfigFile("./sim.cnf");

    while (Global.repeatedRuns != 0) {

        Global.LOGGER.info("=============================================================================");
        Global.LOGGER.info("Starting simulation for run " + Global.repeatedRuns + " ...");

        // Re-seed the Random Data Generator
        Global.rand.setSeed(Global.repeatedRuns);
        Global.rdg.reSeed(Global.repeatedRuns);

        // Database initialization and population
        Database db = null;
        Workload wrl = null;

        switch (Global.wrl) {
        case "tpcc":
            db = new TpccDatabase("tpcc");
            wrl = new TpccWorkload("/tpcc.cnf");
            break;

        case "twitter":
            db = new TwitterDatabase("twitter");
            wrl = new TwitterWorkload("/twitter.cnf");
            break;

        default:
            Global.LOGGER.info(Global.run_usage);
            Global.LOGGER.info(Global.abort);
            break;
        }

        // CLuster, Workload Executor, and Metric Collector initialization
        Cluster dbCluster = new Cluster();
        WorkloadExecutor wrlExecutor = new WorkloadExecutor();
        Metric.init(dbCluster);

        // Read TPCC configurations
        wrl.readConfig();

        // Populate initial database                        
        db.populate(wrl);

        // Create a database cluster consisted of a set of physical servers and a consistent hash ring to store the physical data tuples
        WorkloadBatch wb = dbCluster.setup(db, wrl);

        // Workload execution
        wrlExecutor.execute(db, dbCluster, wb, wrl);

        // Close Metric collector
        Metric.close();

        // Proceed for the next iterative simulation run
        Global.LOGGER.info("Simulation ended for iterative run-" + Global.repeatedRuns + ".");
        --Global.repeatedRuns;
    }

    Global.LOGGER.info("Simulation ended.");
}

From source file:net.acesinc.data.json.generator.types.TypeHandler.java

public TypeHandler() {
    rand = new RandomDataGenerator();
}

From source file:com.siemens.industrialbenchmark.util.RandomNumberExpectedValueTest.java

@Test
public void testExpectedValues() {

    long seed = 0;
    Random rand = new Random(seed);
    RandomDataGenerator randomData = new RandomDataGenerator();

    double uniformAverage = 0.0;
    double binomialAverage = 0.0;
    double normalAverage = 0.0;
    double exponentialAverage = 0.0;

    for (int i = 0; i < 1e6; i++) {

        // set current seed
        randomData.reSeed(seed);//from  w ww .ja v  a 2s .  co  m

        // draw random numbers
        double n = randomData.nextGaussian(0, 1);
        double u = randomData.nextUniform(0, 1);
        double b = randomData.nextBinomial(1, 0.5);
        double e = randomData.nextExponential(0.25);

        // average mean random number
        uniformAverage += (1. / (1. + i)) * (u - uniformAverage);
        binomialAverage += (1. / (1. + i)) * (b - binomialAverage);
        normalAverage += (1. / (1. + i)) * (n - normalAverage);
        exponentialAverage += (1. / (1. + i)) * (e - exponentialAverage);

        // draw new seed from global random generator
        seed = rand.nextLong();
    }

    assertEquals(0.5, uniformAverage, 0.001);
    assertEquals(0.5, binomialAverage, 0.001);
    assertEquals(0.0, normalAverage, 0.001);
    assertEquals(0.25, exponentialAverage, 0.001);
}

From source file:net.modelbased.proasense.storage.writer.RandomEventGenerator.java

public RandomEventGenerator() {
    this.randomData = new RandomDataGenerator();
    this.randomNumber = new MersenneTwister();
}

From source file:com.arpnetworking.metrics.generator.metric.GaussianCountMetricGenerator.java

/**
 * Public constructor.//w  w  w .  j  a va  2  s .  com
 *
 * @param mu Mean of the distribution.
 * @param sigma Standard deviation of the distribution.
 * @param wrapped The wrapped generator.
 */
public GaussianCountMetricGenerator(final double mu, final double sigma, final MetricGenerator wrapped) {
    _mu = mu;
    _sigma = sigma;
    _wrapped = wrapped;
    _generator = new RandomDataGenerator();
}

From source file:com.arpnetworking.metrics.generator.metric.UniformMetricGenerator.java

/**
 * Public constructor.//from  www.  j  av a 2  s  . c  o m
 *
 * @param min The minimum of the distribution.
 * @param max The maximum of the distribution.
 * @param nameGenerator The name generator to name the metric created.
 */
public UniformMetricGenerator(final double min, final double max, final NameGenerator nameGenerator) {
    _min = min;
    _max = max;
    _nameGenerator = nameGenerator;
    _generator = new RandomDataGenerator();
}

From source file:com.arpnetworking.metrics.generator.metric.GaussianMetricGenerator.java

/**
 * Public constructor.//w  w  w  .java 2  s . co m
 *
 * @param mu The mean of the distribution.
 * @param sigma The standard deviation of the distribution.
 * @param nameGenerator The name generator to name the metric created.
 */
public GaussianMetricGenerator(final double mu, final double sigma, final NameGenerator nameGenerator) {
    _mu = mu;
    _sigma = sigma;
    _nameGenerator = nameGenerator;
    _generator = new RandomDataGenerator();
}