LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can LabVIEW generate random numbers according to any pdf or histogram?

Solved!
Go to solution

I would like to know if there is a VI that generate a set of random numbers according to any probability density function, probability mass function or histogram graph (this without knowing explicitly the function).

 

Thanks.

0 Kudos
Message 1 of 4
(6,787 Views)

Not directly, but have a look at the VIs in the Mathematics>>Probability and Statistics>>Probability palette.  There are a bunch of VIs that generate random numbers from known distributions by numerically computing the inverse CDF, and sampling from that using a uniform random number.  You may be able to modify this code by providing your own "function" in place of the PDF in the CDF-inversion routine.

 

Alternatively, sampling from a histogram is pretty straightforward.  Simply compute the cumulative histogram and then sample from that with a random number.  Your friend here is the array function "Threshold 1D array".

 

24618iDCC2ECC76392E0C4

Message 2 of 4
(6,775 Views)
Solution
Accepted by topic author Acoustics

 


@Acoustics wrote:

I would like to know if there is a VI that generate a set of random numbers according to any probability density function, probability mass function or histogram graph (this without knowing explicitly the function).


 

 

If you have a given arbitrary distribution, you can simulate matching random data by thesholding into the normalized integral of the function with a plain random number 0...1.

 

This old post of mine should show you the general procedure and more details. (There is even an old example). Of course make sure that the desired function is all positive, of course. 😉

 

 

Message 3 of 4
(6,767 Views)

Thank you very much altenbach and GregS!

0 Kudos
Message 4 of 4
(6,706 Views)