1 27 28 package org.objectweb.clif.scenario.util.timers; 29 30 import java.util.Random ; 31 32 35 public class GaussianRandomTimer extends RandomTimer { 36 37 private long rand; 38 private int mean; 39 private int deviation; 40 private Random random = new Random (); 41 42 45 public GaussianRandomTimer() { 46 } 47 48 55 public GaussianRandomTimer(int min, int max, int mean, int deviation) { 56 setMin(min); 57 setMax(max); 58 this.mean = mean; 59 this.deviation = deviation; 60 } 61 62 66 public long getDelay() { 67 68 rand = 0; 69 while ((rand == 0) || (rand > getRange())) 70 rand = (long) Math.abs(random.nextGaussian() * deviation + mean); 71 return rand; 72 } 73 74 78 public void delay() { 79 try { 80 Thread.sleep(getDelay()); 81 } catch (InterruptedException e) { 82 e.printStackTrace(); 83 } 84 } 85 86 } 87 | Popular Tags |