03-21-2012 10:55 AM
03-21-2012 01:54 PM
OK. Good idea with the Seed input, here are a couple of VIs.
Bad Riffle.vi -> In case there was any lingering doubt that I put my finger on the algorithm and problem with the existing Riffle.vi I have implemented it fully in G using the Uniform White Noise.vi. Now you can enter a seed value >0 and compare the result with Riffle.vi using the same seed. QED.
Shuffle.llb -> contains a polymorphic vi Shuffle.vi to implement the real Fisher Yates shuffle. I have included a few more datatypes than Riffle (including string and boolean) just for the heck of it. Includes the seed and index outputs like Riffle.
I call it Shuffle and not Riffle because as near as I can tell the existing Riffle.vi (1) Does not Riffle an array (interleaved shuffle) (2) Does not even do what it says in the Detailed Help (Choose two indices at random and swap them) and most importantly (3) does not properly implement an unbiased shuffle. Other than that I really like the VI!
03-21-2012 11:32 PM
Gosh- Darin--
you sound offended!
Of course you are correct.
03-21-2012 11:48 PM
@Darin.K wrote:
OK. Good idea with the Seed input, here are a couple of VIs.
Could you put up some 8.6 versions please? I'd be interested to see.
03-22-2012 12:04 PM
@HR: Here is the Shuffle VI in LV8.6.
@Jeff - Not offended, the detective work is kind of fun in a way. However, I was hoping to discover an off by one type error, a bit disappointed that it was the correct implementation of a flawed algorithm instead of the reverse. It does, for me at least, call into question the other VIs contained in that package.
03-22-2012 05:45 PM
03-22-2012 07:18 PM
Darin.K,
Great job and good find. Thanks to your efforts this was reported to R&D (# 344833) for further investigation.
Thank you for the feedback!
Andrew S.
10-17-2012 01:58 PM - edited 10-17-2012 06:02 PM
Fixed!
I cannot find it mentioned in the list of 2012 bug fixes or in the2012 f1 or f2 patche details, but this has apparently been fixed in 2012. 😄
If I open the existing VI of the first post here, the riffle VI has an obsolete tag and is named "Riffle (obs 2012).vi" to retain the biased functionality for backward compatibility.
Replacing it with the new riffle from the 2012 palette give the correct and expected unbiased result. All's well now! 😄
10-17-2012 02:46 PM
Awesome! One down, Avagadro's number to go!
10-17-2012 04:22 PM
@altenbach wrote:
the riffle VI has an obsolete tag and is named "Riffle (obs 2012).vi" to retain the biased functionality for backward compatibility.
That's a little interesting to me. I'd bet almost every person using it wasn't exactly counting on the bias. I'm not 100% opposed to the resulting fix; in fact I find it a little neat that someone took the time to preserve the biased functionality.