12-07-2012 10:52 AM
Hi,
I am trying to make random selection between 2 options, that any of those two options could be repeated, however, not more than three times.
I have attached my VI. At this point, I can do a random repetition between 2 options but I can't program limiting the repetition for a maximum of three times.
As I am a beginner in labview, I would really appreciate any help or thoughtful reply.
Thanks a lot.
Best,
Mostafa
Solved! Go to Solution.
12-07-2012 11:42 AM
For relatively small numbers of choices and repititions I would go a slightly different route. I would prebuild a simple array which contained the allowed number of each choice (in this case 0,0,0,1,1,1) for two choices (0 and 1) allowed three times max. Then I would shuffle that array. Here is a snippet:
I use the built-in Riffle since it is perfect for this application, except for the small matter of bias which then makes it useless. However, you can go to this thread:
http://forums.ni.com/t5/LabVIEW/Riffle-is-Biased/m-p/1921103#M642990
and find my replacement Shuffle.llb which has a polymorphic VI for doing a proper shuffle. Replace Riffle with that and you are good to go.
12-08-2012 05:40 PM
Thank you very much Darin, that was really helpful 🙂
However, this program limits the numbers of trials that I can do for just 6 trails. I actually want to do 200 trials. I have tried to repeat the whole program by putting it in a for loop but found that the condition of have no more than 3 repetition in a row might be disrupted as every time the program repeated it does not take into consideration the order of elements from the last iteration.
I wonder if you have any idea about how to stick to the same rules however with more elements. Thank you very much for your help 🙂
12-08-2012 07:32 PM
It sounds like I misunderstood your problem. Now it seems you want to limit the length of the longest run in the data (equal consecutive values) to three. You can do the following:
Just keep a count of the current run length and invert the current value if the run is too long.
12-10-2012 10:39 AM
thanks alot that's exactly what I have been trying to figure out since a while
I'm reallly very thankful 🙂