Generate RTT values
I'm writing a Java applet where I should be able to simulate a connection between two hosts. Hence I have to generate packet round-trip times at random.
These RTTs can go from ~0 to infinity, but are typically oscillating开发者_JAVA百科 around some average value (i.e. an extremely large or small value is very improbable but possible). I was wondering if anyone had an idea of how I could do this?
Thanks in advance
You're going to have to select a reasonable disribution from which to draw (pseudo) random values. A gamma distribuition might make some sense as it seems to satisfy your requirements. You could also use a (left) truncated normal distribution.
The Apache Commons-Math library for Java has code for the gamma and normal (aka Gaussian) distributions. When using a normal distribution RNG for picking values from a truncated normal distribution, simply reject undesired draws (i.e. when you pick x <= 0, pick again).
精彩评论