ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

random selection repeatition

Solved!
Go to solution

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

 

0 Kudos
Message 1 of 5
(3,448 Views)
Solution
Accepted by topic author Nashaat

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:

 

RiffleSelection.png

 

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.

0 Kudos
Message 2 of 5
(3,431 Views)

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 🙂

0 Kudos
Message 3 of 5
(3,400 Views)

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:

 

MaxRun.png

 

Just keep a count of the current run length and invert the current value if the run is too long.

0 Kudos
Message 4 of 5
(3,392 Views)

thanks alot that's exactly what I have been trying to figure out since a while

I'm reallly very thankful 🙂

 

0 Kudos
Message 5 of 5
(3,364 Views)