Jump to content
Phillip Brooks

Select Random Array Indices

Recommended Posts

I was recently cleaning up some awful code and extracted this piece as a general purpose function.

I have problems with using VI Package manager at work and also still run LabVIEW 8.6.1, so I don't know if a recent OpenG function similar to this exists.

post-949-0-52110000-1315422649_thumb.png

Select Random Array Indices.vi

Share this post


Link to post
Share on other sites

What are the use cases for choosing random elements in an array?

Personally, I've only had to do this once, and it was in an NIWeek coding challenge about 6 years ago :lol:

Just thinking.... could this be further generalized to a function that chooses a random integer between two ranges (for example an array element index between 0 and Length - 1)? Maybe it would be good to add such general purpose functionality to the OpenG Random Number within Range (adding the ability to work with integers), as opposed to the more specific use case of choosing random elements in an array.

  • Like 1

Share this post


Link to post
Share on other sites

My use case was for product sampling. We receive lots/batches of serialized products that we test for performance and prgramming. The sample size depends upon the previous lot/batch success rate. I perform the selection in Labview and update a database on pass/fail.

We also have a device that is characterized by a polynomial. A lookup table for every step setting was in excess of our storage capacity. We collect a series of points, perform a fit, and then randomly test a couple of points against the polynomial for accuracy.

Wouldn't this work like the Riffle function in LabVIEW (where your code takes the first n outputs)

Ton

When I took this random elements code (really badly done) and rewrote it, I remembered an NI forum post about randomizing a deck of cards and couldn't remember the name of the function. I guess riffle used with array subset would be the ' NI' way to do it.

Thanks for reminding me!

Share this post


Link to post
Share on other sites

I looked at some of the riffle posts on the dark side and noticed that riffle seems to be part of the FDS. Base folks wouldn't have this function to use.

The other thing is that the array to be riffled is modified and must by an array of DBL, CDB or I32. My example does not use the data array as an input, only the size and number of elements to select. It would work for an array of clusters etc...

Maybe an OpenG riffle function for base users and arrays of other types is useful?

Share this post


Link to post
Share on other sites

Partially inspired by this thread, the latest array XNodes package in the code repository contains an XNode that randomizes an array of any type. The algorithm is trivial - bundle with a random number, sort, and unbundle. I don't return the randomised indices but it would be pretty easy. I'm also not completely convinced about the robustness of the algorithm since the element value gets used as a 'tie-breaker' if there are two identical random numbers.

Share this post


Link to post
Share on other sites

I used to use Riffle for this, but now I sometimes look for excuses to use the following since it is so darned cool:

http://forums.ni.com/t5/LabVIEW-Developers-Feature/Now-available-for-download-quot-Randomize-1D-Array-vi-quot-that/m-p/1159329/highlight/true#M462

Can't help but feel like NI is taunting us though...

Share this post


Link to post
Share on other sites

I used to use Riffle for this, but now I sometimes look for excuses to use the following since it is so darned cool:

http://forums.ni.com...light/true#M462

Can't help but feel like NI is taunting us though...

Now that you bought it up...

This has been on my radar as it sure would make distributing OpenG (and my own) Array code easier.

I checked and the idea exists on the IE, so I would really love to see Provide a Better Way to Implement a Polymorphic VI voted up enough to get enough visibility.

I like what AQ has posted and would love to see it in 2012.

What I really want to do is run a campaign for it like AQ and Darren did for Create SubVI From Selection.

Now, I just need to find some high profile devs to help promote it and make it happen... :shifty:

Share this post


Link to post
Share on other sites

I checked and the idea exists on the IE, so I would really love to see Provide a Better Way to Implement a Polymorphic VI voted up enough to get enough visibility.

I like what AQ has posted and would love to see it in 2012.

For a long time now, me and a couple other guys here have dreamed of being able to drop a "black terminal" which will literally take any type without coercion. I saw AQ's post when he first wrote it and I was excited to see that we're getting closer to having that feature. I wish I knew more about how it was written.

  • Like 1

Share this post


Link to post
Share on other sites

For a long time now, me and a couple other guys here have dreamed of being able to drop a "black terminal" which will literally take any type without coercion. I saw AQ's post when he first wrote it and I was excited to see that we're getting closer to having that feature. I wish I knew more about how it was written.

Well, lets get this party started then...

Share this post


Link to post
Share on other sites

For a long time now, me and a couple other guys here have dreamed of being able to drop a "black terminal" which will literally take any type without coercion. I saw AQ's post when he first wrote it and I was excited to see that we're getting closer to having that feature. I wish I knew more about how it was written.

There must be a LabVIEW.ini key that let's you create these.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.