How to implement equal no. of switch and non-switch trials

You may be interested in my new Randomisation without repetition demo. I deal with the dead end issue by adding additional trials if the experiment is about to get stuck. It’s not a perfect solution, but I wanted to present an alterative to the approach of preloading the trials and reshuffling until the order passes the criteria.