cancelar
Mostrando resultados para 
Pesquisar então 
Você quer dizer: 

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
Mensagem 1 de 11
4.777Exibições
Something like this would work (it may be a little goldbergian)


Message Edited by JeffOverton on 05-14-2008 02:53 PM
0 Kudos
Mensagem 2 de 11
4.770Exibições
Here is a slightly updated version of an exclusive random integer VI we developed in LV 1.2.

Lynn
Baixar tudo
0 Kudos
Mensagem 3 de 11
4.760Exibições

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
Baixar tudo
Mensagem 4 de 11
4.747Exibições
Trying to win the lottery? Piscadela do Smiley

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
Mensagem 5 de 11
4.742Exibições
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
Mensagem 6 de 11
4.738Exibições
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. Piscadela do Smiley
0 Kudos
Mensagem 7 de 11
4.735Exibições
And, continuing on the educational demonstrations, here's another way to check for duplicates:

0 Kudos
Mensagem 8 de 11
4.721Exibições
However, if it's a lottery, order is important.
0 Kudos
Mensagem 9 de 11
4.673Exibições

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
Mensagem 10 de 11
4.650Exibições