Here you can find the source of randomSleep(int duration, TimeUnit timeUnit)
public static int randomSleep(int duration, TimeUnit timeUnit)
//package com.java2s; //License from project: Apache License import com.google.common.base.Throwables; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; public class Main { public static int randomSleep(int duration, TimeUnit timeUnit) { int sleepTime = ThreadLocalRandom.current().nextInt(duration); try {/*from w w w .java 2 s .c o m*/ timeUnit.sleep(sleepTime); } catch (InterruptedException e) { Throwables.propagate(e); } return sleepTime; } }