trirnd
randomValue = TRIRND(minVal, topVal, maxVal);
The distribution is defined by:
- a minimum and a maximum value
- a "top" value, with the highest probability.
The distribution is defined with zero probability at minVal-1 and maxVal+1, and with highest probability at topVal. Hence every value in the range (including the maximum and minimum values) have a non-zero probability to be included, whatever topValue is.
The output is a random integer.
randomMatrix = TRIRND(minVal, topVal, maxVal, nrow, ncolumns)
returns a (nrow x ncolumns) matrix of random integers.
NOTES:
* This is a numeric approximation, so use with care in "serious" statistical applications!
* Two different algorithms are implemented. One is efficient for large number of random points within a small range (maxVal-minVal), while the other is efficient for large range for reasonable number of points. For large ranges, there is a O(n^2) relation with regard to the product of range*number_of_points. When this product reach about a billion, the runtime reach several minutes.
* To inspect the resulting distribution, plot a histogram of the resulting random numbers, e.g. "hist(trirnd(1,87,100,10000,1),100)".
Written by L.Cavin, 20.10.2004, (c) CSE & ETHZ
This code is free to use and modify for non-commercial purposes.
Zitieren als
Laurent Cavin (2024). trirnd (https://www.mathworks.com/matlabcentral/fileexchange/3920-trirnd), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Plattform-Kompatibilität
Windows macOS LinuxKategorien
- AI and Statistics > Statistics and Machine Learning Toolbox > Probability Distributions > Continuous Distributions > Uniform Distribution (Continuous) >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.0.0.0 | The old algorithm was not efficient for generating random number in a large interval. A second algorithm has been added for covering such cases. |