How do I generate a random number between two numbers with using a distribution
Mostra commenti meno recenti
I I know that we can define distribution in the random command, but the random numbers I generate with the random command are integers. I'm using the rand command for decimal random numbers and this time I can't define a distribution. In short, how can I create a normal distribution or triangular distribution of 100 random numbers consisting of decimal numbers?
Risposta accettata
Più risposte (1)
Paul
il 22 Mar 2022
1 voto
Emre,
The statement that the the random() command only generates integers doesn't sound correct. The doc page shows an an example of generating random numbers from a Weibull diistribution which are not integers. Can you post an example that illustrates the behavior?
For a standard normal distribution you can use randn(), and then adjust the outputs for whatever mean and variance is desired. Or use normrnd() in the Statistics and Machine Learning Toolbox, or other options in that toolbox. That toolbox supports many distributions, including the Triangular distribution, for which you can get the pdf, cdf, random numbers, and lots of other interesting things.
2 Commenti
Here's an example using Stats Toolbox functionality
pd = makedist('Triangular',0,20,100)
rng(100);
v = random(pd,100000,1);
histogram(v,'Normalization','pdf')
Emre Can Yilmaz
il 22 Mar 2022
Categorie
Scopri di più su Random Number Generation in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


