LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

¿there is another form to do this?

Solved!
Go to solution

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

0 Kudos
Message 1 of 17
(3,146 Views)
Solution
Accepted by angoav98
Message 2 of 17
(3,144 Views)

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.

 

0 Kudos
Message 3 of 17
(3,143 Views)

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

0 Kudos
Message 4 of 17
(3,137 Views)

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)

 

 

Download All
Message 5 of 17
(3,119 Views)

angoav98 wrote:

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


A few more comments on your code:

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
(3,112 Views)

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

 

0 Kudos
Message 7 of 17
(3,108 Views)

@Ravens Fan wrote:

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



... 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.

0 Kudos
Message 8 of 17
(3,105 Views)
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.
0 Kudos
Message 9 of 17
(3,096 Views)

@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. 😉

0 Kudos
Message 10 of 17
(3,093 Views)