LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Do not want to repeat the same number in a while

Hi everyone,

im trying to know how can i do for not repeating a number that has already came out inside a while. I know how to do it for the previous number (just adding a shift register), but i want to know how to not repeat any number that has already came out in the X iteration while loop.

In my case, i have a while loop with 8 iterations, and i generate a random integer number between 0 and 7. I just want that, if in any other iteration the number is repeated, generate a new one until you get the new one number

 

Thanks

0 Kudos
Message 1 of 9
(4,413 Views)

is your means some thing like this vi that I attach

0 Kudos
Message 2 of 9
(4,392 Views)

I have something like the VI i attached.

I just want that "Integer" shows all numbers between 0 and 7 randomly, without repeating anyone.

0 Kudos
Message 3 of 9
(4,378 Views)

this vi create 8 diffrent random data and allarm you when you get all 8 number with random mode 

0 Kudos
Message 4 of 9
(4,359 Views)

Thanks you very much! I'll take it! 🙂

0 Kudos
Message 5 of 9
(4,338 Views)

gregoryj method elso is true and you can selected as sloution 

0 Kudos
Message 7 of 9
(4,284 Views)

If the number is not repeating then it is not random, because random numbers can and will repeat. Just something to be aware of. I assume you don't actually want a random number, but rather want all the numbers from 1 to N in a random order.


___________________
Try to take over the world!
0 Kudos
Message 8 of 9
(4,247 Views)

"Riffle" is what you do to a deck of cards when you divide them into two stacks, lift the corners, and "intermesh" them into a new order -- "shuffling the deck".  It has come to mean "provide a random ordering of the numbers 1 .. N".  There is a "Riffle Algorithm" to do just this, one that can be proven to be the "best" (in that (a) every card can be shown to have probability 1/N to be in the i-th position and (b) it involves the minimum number of random integer generations and swaps.  About 5 years ago, Darren Nattinger gave a very entertaining talk at NI week about "fast LabVIEW coding" that included the "Texas Lotto" challenge -- which algorithm that he showed for generating (I'm not sure of the numbers here, but) 5 "Texas Lotto" numbers from a set of 1 to 52 was the fastest.  Most of the audience (including me) guessed the wrong algorithm of those he showed, but I raised my hand and said "But I know how to do it even faster ...".  On the plane ride home, I coded mine (which involved a Riffle algorithm), sent it to him, and he agreed.

 

So depending on your usage, go with Gregory.  Generate your "deck of cards" by creating an array of numbers 1 .. N, riffle it, then start "dealing cards" by selecting the numbers from positions 1 .. N until you have "exhausted the deck".  If you need more "random samples", shuffle the deck again.

 

Do note tst's (true) comment that this is subtly different from randomly selecting a number from 1 to N multiple times.  If I have a deck of cards and shuffle it each time I pick a card (placing my last card back in the deck), I could choose the Ace of Spades four times in a row, it would just be mathematically highly unlikely.  If I dealt 4 cards from a deck, however, I could only deal one Ace of Spades ...

 

Bob Schor

0 Kudos
Message 9 of 9
(4,209 Views)