As you guessed, it is wrong.
You need to have the equation question before the two groups, otherwise it won't work.
Lets say you will create the equation question and give it the question code "Q1".
Then you put this code into the equation question:
What does this code do? It checks if the equation question Q1 has been triggered already and already has a random number set (isempty(Q1)). If it is empty, then it will create a random number of 1 or 2. However, if the random number is already set in the question Q1, then it will do nothing, but just use its own value. Why so complicated? why not only use {floor(rand(1,2))} to create a random number? Because then whenever the equation is triggered a new random number is created, which of course we wouldn't want. We want it to be set once the first random drawing was done.
Then in the following question, in your case the groups actually, you insert in the relevance equation of the respective groups something like {Q1==1} to show/hide the group when Q1==1, e.g. for the treated group, and {Q1==2} to show/hide the control group.