Answer the question
In order to leave comments, you need to log in
How to generate random numbers in a range according to different distribution laws?
Hello colleagues!
I am writing a network traffic generator, where the size of generated packets obeys one of the distribution laws, the problem is that the size should range from 42 to 508, and distribution sampling can give completely different ranges. Are there any methods to get a specific distribution in a specific range of values? I will be very grateful for the answers!
Answer the question
In order to leave comments, you need to log in
One of the purely specific methods for a discrete random variable (I will show on the example of 5 values):
Let it be necessary to obtain five values [A..E] with probability ratios 2:7:5:3:4.
1. Construct the cumulative sum of probabilities: 2:9:14:17:21
2. Divide the obtained values by the final sum (21): 0.095:0.429:0.667:0.809:1
3. Generate a pseudo-random value X in the range [0:1) with an even distribution.
4. Let's go through the resulting array. As soon as X becomes less than the next element of the array, we have the desired element.
the problem is that the size should range from 42 to 508
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question