LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview function similar to numpy.random.normal

Solved!
Go to solution

I am trying to generate random numbers with an underlying gaussian distribution, similar to the output of the numpy (python) function numpy.random.normal.
Specifically, I want to supply a mean and variance, and have the function return numbers close to the mean with a higher probability than those further away.
I am at  a complete loss about this. None of the supplied 'Gausian VIs' seem to be able to do this and I dont know how to implement his myself.
Thanks. Doug

0 Kudos
Message 1 of 5
(3,452 Views)

Gaussian White Noise PtByPt.vi and Gaussian White Noise.vi both have a standard deviation as input.

 

AFAIK, variance is (std.dev)^2... Std. Dev is sqrt(variance).

 

The mean value can simply be added to the output. Normally, the noise is centered around 0, which is the mean.

Message 2 of 5
(3,429 Views)
Solution
Accepted by topic author dougbockILT

...and here's what it looks like

 

-Kevin P

 

image.pnggaussian distribution.png

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 3 of 5
(3,410 Views)

You did not say if you want one random number at a time or an entire array full of them. The above solution gives you an array.

To generate a single such random number, you could write your own subVI using the Box-Muller algorithm. It takes pairs of even distributed random numbers (0..1) to obtain one (or even two) normalized random numbers that can be shifted and scaled for the desired mean and standard deviation. Your subVI would take mean and stdev as inputs and return a corresponding random value.

Message 4 of 5
(3,395 Views)

The first function (maybe both) used by Kevin is available as PtByPt function. You can use that to get single points.

0 Kudos
Message 5 of 5
(3,348 Views)