Jump to content

Select Random Array Indices


Recommended Posts

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
Link to comment

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!

Link to comment

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?

Link to comment

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.

Link to comment

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:

Link to comment

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
Link to comment

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...

Link to comment

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
Link to comment

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.