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

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

Introduction

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

Prototype

public long nextLong(long lower, long upper) throws NumberIsTooLargeException 

Source Link

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);/* w  w  w  .  ja  v  a 2s . co 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();
    }
}