Example usage for org.apache.commons.math3.random RandomDataImpl nextExponential

List of usage examples for org.apache.commons.math3.random RandomDataImpl nextExponential

Introduction

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

Prototype

public double nextExponential(double mean) throws NotStrictlyPositiveException 

Source Link

Document

Algorithm Description: Uses the Algorithm SA (Ahrens) from p.

Usage

From source file:io.prometheus.client.examples.random.Main.java

public static void main(final String[] arguments) {
    Registry.defaultInitialize();
    final Server server = new Server(8181);
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);/*from  w  w w . j a  v a  2 s  . c  o  m*/
    context.addServlet(new ServletHolder(new MetricsServlet()), "/");

    new Thread() {
        @Override
        public void run() {
            final RandomDataImpl randomData = new RandomDataImpl();

            try {
                while (true) {
                    rpcLatency.add(ImmutableMap.of("service", "foo"), randomData.nextLong(0, 200));
                    rpcLatency.add(ImmutableMap.of("service", "bar"), (float) randomData.nextGaussian(100, 20));
                    rpcLatency.add(ImmutableMap.of("service", "zed"), (float) randomData.nextExponential(100));
                    rpcCalls.increment(ImmutableMap.of("service", "foo"));
                    rpcCalls.increment(ImmutableMap.of("service", "bar"));
                    rpcCalls.increment(ImmutableMap.of("service", "zed"));
                    Thread.sleep(1000);
                }
            } catch (final InterruptedException e) {
            }
        }
    }.start();

    try {
        server.start();
        server.join();
    } catch (Exception e) {
        e.printStackTrace();
    }
}