01-16-2016 06:41 AM
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
01-16-2016 07:19 AM
is your means some thing like this vi that I attach
01-16-2016 07:35 AM
I have something like the VI i attached.
I just want that "Integer" shows all numbers between 0 and 7 randomly, without repeating anyone.
01-16-2016 07:49 AM
this vi create 8 diffrent random data and allarm you when you get all 8 number with random mode
01-16-2016 08:36 AM
Thanks you very much! I'll take it! 🙂
01-16-2016 10:16 AM
01-16-2016 12:27 PM
gregoryj method elso is true and you can selected as sloution
01-16-2016 11:37 PM
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.
01-17-2016 07:35 AM
"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