randomTriangular¶
Generates pseudorandom numbers from a triangular distribution on the interval (0, 1).
Synopsis¶
randomTriangular (nRandom)
Required Arguments¶
- int
nRandom
(Input) - Number of random numbers to generate.
Return Value¶
An array of length nRandom
containing the random deviates of a
triangular distribution.
Description¶
Function randomTriangular
generates pseudorandom numbers from a
triangular distribution over the unit interval. The probability density
function is \(f(x)=4x\), for \(0\leq x\leq 0.5\), and
\(f(x)=4(1-x)\), for \(0.5<x\leq 1\). An inverse CDF technique is
used.
Example¶
In this example, randomTriangular
is used to generate five pseudorandom
deviates from a triangular distribution.
from numpy import *
from pyimsl.stat.randomTriangular import randomTriangular
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix
n_random = 5
randomSeedSet(123457)
r = randomTriangular(n_random)
writeMatrix("Triangular random deviates", r, noColLabels=True)
Output¶
Triangular random deviates
0.8700 0.3610 0.6581 0.5360 0.7215