06-24-2010 04:39 PM - last edited on 09-29-2011 12:40 PM by srdfrn
Attached to this post is "Randomize 1D Array.vi". You can wire any array type to the input and get that array type from the output, just like you can with the built-in Sort 1D Array function. The randomized order is guaranteed to be uniform distribution. The VI is saved in LV 2009, though the VI may have problems in a Built Application unless you have LV 2009 SP1.
I generated this VI after seeing this Idea Exchange request for such functionality.
This VI may excite those of you who have long wanted to "write a VI once for type A and have it just work for types B, C, D, etc." This is an experimental tech in R&D, and this post marks the first time a VI with this ability is generally in the wild. Unfortunately, the ability to build VIs of this type appears to be a long ways off -- it's a hard problem, especially once subVIs start getting involved. But the "Randomize 1D Array.vi" is a simple enough VI (with no subVIs) that I was able to generate it with our in-house tools. And I'm sorry to disappoint everyone -- the VI is password protected.
At the moment, we call this kind of VI a "generic VI", because the terms "template VI" and "polymorphic VI" are already taken by other features. "Generic" doesn't really say anything about what this kind of VI actually does, so if anyone has a better suggestion for these types of VIs, post them here. Keep in mind: it will be multiple versions of LV before this feature sees the light of day.
Note: This beta test is finished; the VIs are no longer available for download because instabilities have been identified.
06-24-2010 05:38 PM
Fantastic! Not so much for the routine itself (which I'd rarely use) but for the technology. Does this ability extend to transparently accepting arrays of multiple dimensions?
However, given that you're being such a tease about it all (the candy is just out of reach for several YEARS...) I wonder if you'll take other simple, no-subVI, suggestions and create "generic" VIs for them? Most (or all) of the OpenG array VIs would fit this category, as would this routine I wrote for resampling a 1D array:
06-24-2010 06:10 PM
Agreed, the random array, whoop-de-doo, but a Chameleon VI? That's stellar.
06-24-2010 06:12 PM
I may or may not speak for others when I say, "Screw SubVIs". If I could do this for even simple VIs I'd be very excited. I'll wait years for the full-blown version, but this is too good to sit on for that long.
06-24-2010 06:17 PM
I poked around... If you look in the LabVIEW Data folder, you'll find an lvgen file for Randomize 1D Array. This file can be opened in the LLB browser and shows all of the instance VIs. It appears that the LabVIEW editor is creating a copy of the original VI for every type wired in (and keeping them in this LLB). The hash in the instance name is probably an MD5 of the type descriptors, or similar.
06-24-2010 07:06 PM
I am unable to post the VI, but here are the results from a validation I performed on the probability distribution of the randomness. Apparently, the function is very sensitive to order, and certain starting element indices have strong tendencies to appear or not appear in a given resultant index. See below:
And here are the results:
Breakdown: First result shows the last element in original array is extremely likely to end up in the first index, the middle graph is a representative that all three middle indices will never end up in the first index of the result, and the final graph shows that the first element properly will randomly appear in any one of the five resultant indices.
06-24-2010 07:19 PM