1 27 28 package org.objectweb.clif.scenario.util.timers; 29 30 import java.util.Random ; 31 32 35 public class NegativeExponentialTimer extends RandomTimer { 36 37 private long rand; 38 private Random random = new Random (); 39 private int mean; 40 41 44 public NegativeExponentialTimer() { 45 } 46 47 53 public NegativeExponentialTimer(int min, int mean) { 54 setMin(min); 55 this.mean = mean; 56 } 57 58 62 public long getDelay() { 63 double r = random.nextDouble(); 64 if (r < (double) 4.54e-5) 65 return ((long) (r + getMin())); 66 return ((long) ((((double) - mean) * Math.log(r)) + getMin())); 67 } 68 69 73 public void delay() { 74 try { 75 Thread.sleep(getDelay()); 76 } catch (InterruptedException e) { 77 e.printStackTrace(); 78 } 79 } 80 81 } 82 | Popular Tags |