Distribution

duncan smith buzzard at urubu.freeserve.co.uk
Tue Mar 20 16:19:28 EDT 2012


On 20/03/12 04:31, prince.pangeni wrote:
> Hi all,
>     I am doing a simulation project using Python. In my project, I want
> to use some short of distribution to generate requests to a server.
> The request should have two distributions. One for request arrival
> rate (should be poisson) and another for request mix (i.e. out of the
> total requests defined in request arrival rate, how many requests are
> of which type).
>     Example: Suppose the request rate is - 90 req/sec (generated using
> poisson distribution) at time t and we have 3 types of requests (i.e.
> r1, r2, r2). The request mix distribution output should be similar to:
> {r1 : 50 , r2 : 30 , r3 : 10} (i.e. out of 90 requests - 50 are of r1
> type, 30 are of r2 type and 10 are of r3 type).
>     As I an new to python distribution module, I am not getting how to
> code this situation. Please help me out for the same.
>
>    Thanks in advance
>
> Prince

Robert has given you a very good answer. The easiest way is to generate 
interarrival times using an exponential distribution, then for each 
event select the type from a categorical probability mass function. 
Perhaps the easiest and most efficient approach for the latter using 
your 'mix distribution' above is to create a list containing 5 instances 
of r1, 3 of r2 and 1 of r3. Then select the type by generating a random 
index into the list. It is not an ideal solution generally, but good 
when the parameters do not change and the required list is small.

Duncan



More information about the Python-list mailing list