04-28-2010 09:15 PM
Solved! Go to Solution.
04-28-2010 09:21 PM
What is this list of numbers? Is it an array?
Your description doesn't do justice for what you are trying to do. Can you post some examples of what you are getting and how you want to make it behave differently? Perhaps even post the VI you've created so far?
04-28-2010 09:35 PM
So, I am generating, maybe 4 different numbers (in this case like 5-8) in a random order.
In my vi I'll get something like this:
6 5 5 8
when I want something like this:
6 5 7 8
I keep getting duplicates in my array.
04-28-2010 09:51 PM
Set up your array in order. Then do your randomization by shuffling the values between random indices some N number of times.
I'm sure there are examples on the forum where someone has done that. I just haven't found one yet by searching.
04-28-2010 09:57 PM
04-28-2010 10:05 PM
04-28-2010 10:20 PM - edited 04-28-2010 10:26 PM
shuffle, permutation possibly monte carlo simulation.
But none of those words gave me the results I was expecting in a forum search.
The algorithm would be easy to set up. You could go through the array each element at a time and swap it with an element at a random location.
You could pick two random locations and swap them with each other.
Exactly how many times to loop to feel like you have a good random shuffle could be a math science in itself. I think if you did this looping for the number of elements you are dealing with times a factor of 5, you'd be in pretty good shape.
I found a good example that looks even simpler than what I'm proposing.
04-28-2010 10:36 PM
So I should use an index array. I can't quite figure out how to eliminate used indexes.
04-28-2010 10:41 PM
Oops, I totally missed the example you sent me. Yes, that's exactly what I need to do thank you!
04-29-2010 12:16 AM
Chod wrote:So I should use an index array. I can't quite figure out how to eliminate used indexes.
If you do use the method of swapping indices, it doesn't matter whether it's been used before or not. If you swap 1 and 5 now, later on you swap 5 and 6, 6 and 2, 2 and 1. It all doesn't matter. It just means whatever values were in those particular indices get swapped around more often than others. There is the potential that a particular index never gets touched. With a sufficient number of swaps, the arrangement of values could be considered random.
What I like about that example I found later was that you really don't have to specify any number of swaps. It allows for the random number generator and its ability to you give an infinitesimally small resolution on the number between 0 and 1 (at least to the resolution of a double floating point number which means 32 bits of resolution) to help rearrange the elements with just one passage through the array whether it is a few elements or a very large number of elements. With my example and using indices, you'd have to scale the random number from 0 to 1 to 0 to N and round it to integers to randomly select indices to move. And you'd want to do this whole process multiple times through the array since you'd only have a 1 in N choice of where the element would fall in the array as opposed to a 1 in 2^32 choice of where to place the element relative to the others.