Random number generation with min, max and mean

39 views (last 30 days)
Hello, I want to generate random numbers for probability function with using mean, maximum and minimum values. For example, I know the average probability of X is 0,4. What I want is to reate random numbers between 0 and 1 with most of them close to 0,4. Is there a function like this? Does this contradict the randomness of random numbers? Thank you for your help!
  6 Comments
Walter Roberson
Walter Roberson on 25 May 2022
Edited: Walter Roberson on 25 May 2022
beta distribution can satisfy the min max mean requirements. You would take
xprime = (x-min) /(max-min)
and beta() that. The mean is at alpha/(alpha+beta) so for example alpha = 2 beta = 3 gives mean at 2/5. If you have a desired standard deviation then the formula for the variance together with the formula for the mean would give you a pair of simultaneous equations to allow you to solve for alpha and beta.
Torsten
Torsten on 25 May 2022
Edited: Torsten on 25 May 2022
To account for the effect of a risk event on the schedule, you must know the general probability that a risk event happens at time t, not the probability of what kind of risk event happened under the condition that it has happened. So to know that 10% of the risk events are due to fire and 85% are due to worker accidents does not help much in your case.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 25 May 2022
Edited: John D'Errico on 25 May 2022
Sigh. I've probably seen different variations of this question asked at least many hundreds of times over the 40+ years I have been answering questions and doing consulting. The problem is, it has no answer. At least not one that you will be happy with in the form you asked it. That is, there are infinitely many distributions one might choose that have the properties you describe.
For example, a beta distribution is a nice example, or perhaps a truncated normal distribution. They could both have the general curve shape you describe for the PDF. But even in those two specific cases there are infinitely many choices one could make, ALL of which satisfy the requirements. And you have not given sufficient information to choose between anything.
For example, consider a beta distribution.
The one they describe there is defined on a support of [0,1], so it is perfect for your problem. That beta distribution has a mean of
alpha/(alpha + beta)
so as long as the two distribution parameters satisfy the relationship:
0.6*alpha = 0.4*beta
then the mean will be 0.4.
Since you seem to want a unimodal distribution, then they both need to be greater than 1 too. But that does not restrict things by a lot. There are still infinitely many distributions that will do as required. Conveniently, the stats toolbox beta distribution is also defined on a support of [0,1], so that is good. Here are a few distributions that all have the necessary properties:
fplot(@(X) betapdf(X,1.6,2.4),[0,1])
hold on
fplot(@(X) betapdf(X,2,3),[0,1])
fplot(@(X) betapdf(X,4,6),[0,1])
fplot(@(X) betapdf(X,6,9),[0,1])
fplot(@(X) betapdf(X,10,15),[0,1])
grid on
legend('[1.6,2.4]','[2,3]','[4,6]','[6,9]','[10,15]')
Again, as long as alpha is exactly 2/3 of beta, then the mean will be 0.4. There would be no beta distribution where the mode AND the mean will be exactly 0.4, but as the parameters grow large in that ratio, the mode will approach 0.4 asymptotically.
I could surely do something similar for a truncated normal distribution or many others, or I could hack up an example with the mode and mean both at 0.4, though that would require me to think for a few seconds more, and it is still too early in the AM here for the brain cells to fully function.
Still, the fundamental problem is you have not said enough in your requirements. Pick any of the distributions I have shown, and they will all have a mean of 0.4, and the mode will not be too far from 0.4 either. They are all unimodal distributions.
  2 Comments
Nevzat Can Yerlikaya
Nevzat Can Yerlikaya on 25 May 2022
Edited: Nevzat Can Yerlikaya on 25 May 2022
Thank you for this specific and insightful answer. My main goal is the create a schedule overrun for a construction project. I have different work items and for each work items, I have few risk items. I want to calculate the probabilistic cost overrun of the projects but as I previously said, I need to do it in a random manner. What I have planned is that I randomly generate around thousand of values between 0 and 1 for every risk factor and with multiplying those values with the schedule overrun of that risk event (for ex, 8 days if there is fire), I would obtain the probabilistic value for that risk event's schedule overrun for the selected randomly generated number (for randomly generated probability of 0,1 ==> schedule overrun will be 0,8 days for fire while for randomly generated probability of 0,2 ==> schedule overrun will be 1,6 days for fire) .I will do this for thousands of time and obtain a histogram. Then I will combine that with starting point end points etc but that part I know how to do. The main thing I want to do is for ex, I found prob. of fire occuring is 0,2, obtained from the survey I have conducted. The randomly generated values would be close to that. Like, average of the all randomly generated numbers would give something close to 0.2.
I understood your point saying for ex, Beta distribution, you can create infinite pdf with mean having 0,4 and start and end points with 0 and 1. One thing than I am not sure about your suggestion that can I use values obtained from one of that graph as randomly generated. I am new to this topic and as far as I know, Monte Carlo Simulation requires random samples. So by doing this, would I be doing something against the randomness required for MCS or does MCS even require such thing?
Lastly, thank you so much if you've read until here and I was thinking about simplfying my though process and instead of trying to find such a function, I can decide intervals which the random number generater can generate its numbers. For example, for the probability found as 0,2 by surveying; I can randomly generate intervals between 0 and 0,4, but I am afraid whether it would be too deterministic to be probabilistic.
John D'Errico
John D'Errico on 25 May 2022
To generate a 1xn vector of samples with a specific choice of alpha and beta...
n = 10;
betarnd(4,6,[1,n])
ans = 1×10
0.6843 0.4984 0.2694 0.4998 0.1733 0.4502 0.3860 0.4917 0.4207 0.4356
If you have cases where the mean should be different than 0.4, then you can just use the formula I gave, derived from the mean of the beta distribution. Effectively, if you know the mean should be mu, then we have
alpha/(alpha + beta) = mu
so we can solve for alpha as a ratio compared to beta.
alpha/beta = mu/(1-mu)
Thus with mu = 0.2, that tells you to choose any alpha and beta such that alpha is 1/4 of beta, though again they both need to be strictly greater than 1.
fplot(@(X) betapdf(X,1.1,4.4),[0,1])
hold on
fplot(@(X) betapdf(X,1.5,6),[0,1])
fplot(@(X) betapdf(X,3,12),[0,1])
fplot(@(X) betapdf(X,10,40),[0,1])
Again, all of the plotted distributions have a mean of 0.2, and I cannot rationally choose between them.
Based on your last comment, you might choose a simple uniform distribution on some interval. For example, if the mean should be 0.2, you might decide to choose a uniform distribution on the interval [0.1,0.3]. (So then you could use unifrnd, or even rand would suffice with a transformation.) The problem is again, if you choose a uniform distribution with a mean, for example, of 0.2, then how wide a range will you allow? So a uniform distribution on the interval [0.1,0.3] and one on the interval [0.15,0.25] both have means of 0.2. But they are very different in the results you will see. Your problem is still that of non-uniqueness.

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!