LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Random Number Generator with Sub-VI

How do I write a program that generates a specified number of random numbers between 0 and 99 and outputs them as an array. The program should be able to be used as a sub-VI as well. 

0 Kudos
Message 1 of 15
(5,271 Views)

Sounds like a simple FOR loop.  If you are using a newer version of LabVIEW (I think 2017 or newer), there is a Random Number (Range).vi in the numeric palette to give you the range requirement.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 15
(5,252 Views)

@crossrulz wrote:

Sounds like a simple FOR loop.  If you are using a newer version of LabVIEW (I think 2017 or newer), there is a Random Number (Range).vi in the numeric palette to give you the range requirement.


Thanks for that li'l tidbit of information!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 15
(5,237 Views)

Unfortunately, the version requirement is 2019 for "Random Number (Range)". I initially started trying to rule it out of 2018 by the numeric online help, but realised the 2019 changes is a better place to check...

It's listed near the bottom of the New VIs and Functions section.

 

Numeric VIs and Functions
The Numeric palette includes the following new constant and VI:
• Not A Number—Returns the value NaN to the block diagram. [Idea submitted by NI
Discussion Forums member altenbach.]
• Random Number (Range)—Generates a random value from a specified range. You can
use this VI with the following data types: U64, I64, and DBL.


GCentral
0 Kudos
Message 4 of 15
(5,221 Views)

Uniform White Noise.vi outputs an array. The amplitude can be set to 99 to get values between 0 and 99...

 

Presuming 'random' means uniform white noise... Gamma, Poisson, Binominal, Bernouli or Gausian White noise are also available...

0 Kudos
Message 5 of 15
(5,191 Views)

Something like this would work

 

example.png

 

The only reason I added the in range function was because you wanted 0-99. You can adjust where needed to get to what you are looking for.

Tim
GHSP
0 Kudos
Message 6 of 15
(5,180 Views)

You don't need the in range function.  The random number generator creates a number x  where 0<= x < 1.   So 0 to .99999....

 

So multiplying by a 100 gives you the same result with or without the in range and coerce set the way it is.

 

Although I think there was a thread in the past year debating whether the actual implementation truly included 0.

 

If the OP wants an integer between 0 and 99 (typically what these homework problems are looking for, but unclear in this question), then a Round Down (towards 0) should be placed where the in range and coerce is.

0 Kudos
Message 7 of 15
(5,163 Views)

But why program something?

 

Uniform White Noise.png

 

This VI has the added benifit of a seed input (used if init it true). That means it can potentially produce the same random values if desired. This can be convenient for testing.

0 Kudos
Message 8 of 15
(5,138 Views)

I think the reason to program something here is to teach the poster how to program. It is very obvious that they need to understand how things work. It is like in math class when you go through all of the work for proofs only to find out when you are all done that there is a way to do the same thing in two steps. Right?

Tim
GHSP
0 Kudos
Message 9 of 15
(5,131 Views)

@15naj wrote:

How do I write a program that generates a specified number of random numbers between 0 and 99 and outputs them as an array. The program should be able to be used as a sub-VI as well. 


I would recommend to use LabVIEW.

 

This cannot be solved without further information.

 

  • Do you want just integers (whole numbers) or are all values in this range allowed? (e.g. can one number be 55.34876?)
  • What is the desired datatype?
  • What is the desired probability distribution?
  • Does "between" include or exclude the limits (is 0 or 99 allowed)? Zero in not "between", colloquially.
0 Kudos
Message 10 of 15
(5,111 Views)