Java TimeUnit Usage randomNanos(Random rand, int decimalDigits)

Here you can find the source of randomNanos(Random rand, int decimalDigits)

Description

random Nanos

License

Apache License

Declaration

public static int randomNanos(Random rand, int decimalDigits) 

Method Source Code

//package com.java2s;
/*/*from   w ww .  java 2 s.  co m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Main {
    /**
     * TIMESTAMP.
     */

    public static final long NANOSECONDS_PER_SECOND = TimeUnit.SECONDS.toNanos(1);

    public static int randomNanos(Random rand, int decimalDigits) {
        // Only keep the most significant decimalDigits digits.
        int nanos = rand.nextInt((int) NANOSECONDS_PER_SECOND);
        return nanos - nanos % (int) Math.pow(10, 9 - decimalDigits);
    }

    public static int randomNanos(Random rand) {
        return randomNanos(rand, 9);
    }
}

Related

  1. pause()
  2. prettyMillis(long mil)
  3. printTimeMap(Map timeMap)
  4. printTimeString(long time)
  5. printTiming(long start, long end)
  6. rangeOf(final Date date, final int beforeDates, final int afterDates)
  7. roundTimestampToNexDay(long timestamp)
  8. run(Callable task, long timeout)
  9. second(long second)