Code covered by the BSD License  

Highlights from
trirnd

2.66667

2.7 | 3 ratings Rate this file 16 Downloads (last 30 days) File Size: 2.43 KB File ID: #3920
image thumbnail

trirnd

by Laurent Cavin

 

02 Sep 2003 (Updated 25 Oct 2004)

TRIRND generates discrete random numbers from a triangular distribution.

| Watch this File

File Information
Description

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.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
13 Sep 2004 benjamín ojeda

 Me podrían pasar este mismo programa pero en vez de discreto continuo
gracias

31 Aug 2006 Ryan Chan

I tried trirnd(100,200,300) which means 100 as min value, 300 as max value and 200 as highest pobability. However it outputed random number below 100. Something is wrong with the function.

09 Nov 2006 Mongkut Piantanakulchai

You can visit another code page for this

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8054&objectType=file

30 Jan 2007 Andrew Gee

Worked for my purposes, but doesn't work with larger values

Please login to add a comment or rating.
Updates
25 Oct 2004

The old algorithm was not efficient for generating random number in a large interval. A second algorithm has been added for covering such cases.

Tag Activity for this File
Tag Applied By Date/Time
discrete Laurent Cavin 22 Oct 2008 07:07:04
random Laurent Cavin 22 Oct 2008 07:07:04
distribution Laurent Cavin 22 Oct 2008 07:07:04
triangular Laurent Cavin 22 Oct 2008 07:07:04
triangular Marios 06 Feb 2012 15:50:42

Contact us at files@mathworks.com