LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search Random Array of Numbers

How can I search for duplicate numbers in a 1D Array that has Random Numbers In it? The array cannot have duplicate numbers in it, and when it finds the numbers, has to output a boolean to display the numbers (If False It displays, If true, It doesnt display-I have it going to a case Structure). The VI I have attached is My Best Guess at it..Ive tried almost everything I could think of to get it to work.
0 Kudos
Message 1 of 11
(4,613 Views)
Something like this would work (it may be a little goldbergian)


Message Edited by JeffOverton on 05-14-2008 02:53 PM
0 Kudos
Message 2 of 11
(4,606 Views)
Here is a slightly updated version of an exclusive random integer VI we developed in LV 1.2.

Lynn
Download All
0 Kudos
Message 3 of 11
(4,596 Views)

Here's an easy way to pick 6 unique random numbers from 1..43.



Message Edited by altenbach on 05-14-2008 12:25 PM
Download All
Message 4 of 11
(4,583 Views)
Trying to win the lottery? Smiley Wink

Wow. Aside from the fact that it doesn't work, and is also limited to just 6 numbers, there's a far easier way to check if the array has duplicates (using the original method of generating the array, although better methods have been shown):
0 Kudos
Message 5 of 11
(4,578 Views)
While the question was posed differently, I think the main purpose is to generate and array containing six random picks. If we can do that directly, we don't need to check if there are duplicates and try again until we do as attempted in the original code.
 
My code above is sufficient. 😄
 
(As I side note to the original poster, sice we are dealing with integers, you should really stick to blue wires and terminals.)
0 Kudos
Message 6 of 11
(4,574 Views)
Yes, I know. I was presenting the implementation for educational purposes so the user learns to deal with array better. As I noted, there are better ways to generate the array in the first place, and these have already been presented. Smiley Wink
0 Kudos
Message 7 of 11
(4,571 Views)
And, continuing on the educational demonstrations, here's another way to check for duplicates:

0 Kudos
Message 8 of 11
(4,557 Views)
However, if it's a lottery, order is important.
0 Kudos
Message 9 of 11
(4,509 Views)

JeffOverton wrote:
However, if it's a lottery, order is important.
In most (=all) lotteries I've seen, order is not important. The name "lotto" hints to the European versions (e.g. Germany 6 of 49 or similar). For convenience, you can always sort the results.
 
State lotteries are great, they basically amount to a tax on stupidity. 🙂
0 Kudos
Message 10 of 11
(4,486 Views)