取消
显示结果 
搜索替代 
您的意思是: 

random selection repeatition

已解决!
转到解答

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 项奖励
1 条消息(共 5 条)
3,387 次查看
解答
已被主题作者 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 项奖励
2 条消息(共 5 条)
3,370 次查看

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 项奖励
3 条消息(共 5 条)
3,339 次查看

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 项奖励
4 条消息(共 5 条)
3,331 次查看

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

I'm reallly very thankful 🙂

 

0 项奖励
5 条消息(共 5 条)
3,303 次查看