LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

random

Solved!
Go to solution

You don't need to use Riffle (particularly if you don't have it). As RavensFan noted, you can generate an array of numbers from 0 to 999999.  Then all you have to do is "choose one at random", then delete that number from the array (you only need to do this last step because you said you didn't want to ever repeat).  Of course, as you do this, the pool of numbers you are drawing from gets smaller.

 

Do you know how to pick an element at random from an array of size N?  If so, then the problem is essentially solved.

 

BS

0 Kudos
Message 11 of 16
(1,019 Views)

Yes Bob, I know how to pick a random number from an array.  My only question was about the Riffle VI and its availability.  I'm supporting programs using multiple versions of LabVIEW, but never heard about or had occasion to use Riffle.  It's in my versions of LabVIEW 8.2 and 8.5.  I can't find it in 7.1.

0 Kudos
Message 12 of 16
(988 Views)

djs_at_eaton, 

 

Riffle.vi is not available in LabVIEW 7.1 and there is not a similar vi that you can use. Are you able to upconvert your 7.1 code so you can still utilize riffle.vi. 

Maggie
National Instruments
Applications Engineer
ni.com/support
0 Kudos
Message 13 of 16
(946 Views)

To do what he wants to do, namely to choose a six digit number "randomly" without replacement, he doesn't need riffle (in fact, using it will slow him down).  Simply generate the full set of 1000000 numbers in an array and "Choose a number at random from an array of size N and delete it from the array" (thereby reducing the size of the array).

 

True, this will have the overhead of deleting elements from an array.  You Pays Your Money and Takes Your Choice.  I'm not certain what Riffle does (hmm, cancel that, I just looked it up).

 

Better answer -- Don't Use Riffle!  It doesn't (efficiently) solve your problem.  Instead, pretend you are going to do a "Perfect Shuffle".  (This is going to be very close to the algorithm I proposed, above, but without the array deletion).  From an array of size N (start with N = 1000000), choose an entry at random and swap it with the entry at position N.  Decrement N, and repeat as often as you need.

 

It is easy to prove that this "efficiently" samples without replacement from the Set of Size N (and, in the process, "shuffles" the set).  Since the only "cost" of choosing a random sample is "generate a random number" and "swap two entries", it is probably about as fast as you can get.

 

Note, in particular, that Riffle (at least the algorithm described in the Help documentation) is not a Perfect Shuffle!

 

BS

0 Kudos
Message 14 of 16
(938 Views)

Riffle would work just fine, assuming of course he has it.  If he doesn't, then it does no good.  I don't agree that it would slow him down.  What makes you say that?

 

I'm not too concerned about a "perfect shuffle".  You do need to have some X number of shuffles that are based on the number of "cards in the deck".  But how many is that?  There are books written about how many to do that to have a reasonable random probability.  The Riffle function, to my understanding, is basically taking care of all that for you.  But I do think there was bug in the Riffle algorithm that was fixed in later versions of LabVIEW.

 

However, your method of using a random number to grab indexes and then deleting from array to remove them seems like a perfectly logical thing to do and should work quite well.

0 Kudos
Message 15 of 16
(923 Views)

If you play cards, a Riffle Shuffle is what you do when you break the deck in (roughly) half and (roughly) interleave the cards back together.  It is pretty easy to show that if you do this "perfectly" (break the deck exactly in half and exactly interleave the cards), the result is pretty non-random.  In fact, depending on which half "goes down first", you'll get the exact order back in either 52 or 8 perfect shuffles.

 

While some magicians, I think, can do this (and make a trick out of "shuffle 8 times"), I certainly can't.  I think it's been estimated that 7 shuffles is generally "enough" to largely "disorder" the deck.

 

However, the LabVIEW "Riffle" method (at least according to the Help description) is not this at all!  If you have a deck of 52 cards, this involves choosing two cards "at random", swapping them, then repeating this 52 times.  Someone didn't do their homework when they developed this.  For one thing, you are doing twice as many "choose a random number" as the "Perfect Shuffle" algorithm, the same number of swaps, and you have no (mathematical) assurance that your deck is "maximally random" (which the Perfect Shuffle provides).

 

"Why Not The Best?"  [I forgot who said that]

 

BS

0 Kudos
Message 16 of 16
(905 Views)