03-17-2012 03:04 PM
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
Solved! Go to Solution.
03-17-2012 03:21 PM - edited 03-17-2012 03:23 PM
I'd suggest this:
03-17-2012 03:24 PM - edited 03-17-2012 03:27 PM
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.
03-17-2012 03:43 PM
The two solutions is very well. Thaks!!.. I not know very labview, and this ... I learned a lot
03-17-2012 10:24 PM - edited 03-17-2012 10:30 PM
03-17-2012 10:46 PM
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.
03-17-2012 10:52 PM - edited 03-17-2012 10:53 PM
Why build an array in a loop when there is the ramp function?
03-17-2012 11:07 PM - edited 03-17-2012 11:11 PM
@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.
03-18-2012 12:47 AM
03-18-2012 12:59 AM
@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. 😉