# LabVIEW

Showing results for
Did you mean:

Solved!

# ¿there is another form to do this?

I have six random numbers. I need that the six numbers are different, too, i need that the number not greater than 45 and are integer.

Then, i need thet the six number not greater than 45 and are integers and that six number are different.

i attached my file .VI for labview 2009. My program is working  and meets the features that i need

however, I would like to know if you have other form to do this.

Thanks

Message 1 of 17 (318 Views)
Solution
Accepted by topic author angoav98
‎08-27-2015 06:09 PM

## Re: ¿there is another form to do this?

[ Edited ]

I'd suggest this:

Message 2 of 17 (316 Views)

## Re: there is another form to do this?

[ Edited ]

Instead of using an entire screen full of OR functions repeatedly to get down to one boolean, you can use a Compound Arthimetic node and set it for OR.  Stretch the node as far as you need.  Multiple inputs, one node, one output.

You have some issues with your rounding.  As pointed at in your other thread, you should be rounding down.  When you do a round by nearest, you don't have uniform distribution of your random numbers.  You are going to get values from 0 to 45, but the values 0 and 45 have half the chance of being picked as the values from 1 through 44. Round down, you'll have an equal chance of getting 0 through 44.  If you need 1 through 45, then add 1 to the result.

I would do the random number generation in a loop.  As you find each number, build it into an array.  Search for the number in your array.  If the number exists, don't add it, iterate the loop and try again.  If it does exist, then build the new value into the array.  The loop ends once you have 6 numbers in your array.

Edit:  I see X came up with a very similar version while I was doing mine.

Message 3 of 17 (315 Views)

## Re: there is another form to do this?

The two solutions is very well. Thaks!!.. I not know very labview, and this ... I learned a lot

Message 4 of 17 (309 Views)

## Re: ¿there is another form to do this?

[ Edited ]

You did not specify the lower limit, so I assume zero.

All the above solutions seem unecessarily complicated. All you need is the following.

(generate 0..45 integer array -> Riffle -> reshape to 6)

Message 5 of 17 (291 Views)

## Re: ¿there is another form to do this?

angoav98 wrote:

however, I would like to know if you have other form to do this.

Your code will not work, because the random number generators are outside the loop and thus execute only once at the start of the program. All subsequent iteration will read the same value from the tunnel and nothing will ever change until you stop and restart the program. Either it succeeds immediately or fails forever. No loop needed.

Learn about arrays. Whenever you have all these identical operations, you can do it once on an array instead.

Your loop does absolutely nothing except spin as fast as the computer allows, consuming all available power of one CPU core. The code should complete once 6 are found, right? No user iteration needed.

Message 6 of 17 (284 Views)

## Re: there is another form to do this?

[ Edited ]

Why build an array in a loop when there is the ramp function?

Message 7 of 17 (280 Views)

## Re: there is another form to do this?

[ Edited ]

Ravens Fan wrote:

Why build an array in a loop when there is the ramp function?

... because if the problem deals with integers, there should not be any orange wires!

Besides, my loop will be folded into a constant by the compiler because is can be computed fully at compile time.

The ultimate efficiency at run time The ramp subVI does not offer this.

Also the ramp needs three diagram input constants, my loop only one. This is simpler.

Message 8 of 17 (277 Views)

## Re: there is another form to do this?

Why build the array at all when the index output is right next door and you simply pass in an array initialized to the right size.
Message 9 of 17 (268 Views)

## Re: there is another form to do this?

Darin.K wrote:
Why build the array at all when the index output is right next door and you simply pass in an array initialized to the right size.

I cannot really figure out which diagram you are talking about.

Message 10 of 17 (265 Views)