# How to generate two or more unique random variables?

11 months 3 weeks ago #169245
Hello, I want to generate two unique (var1 != var2) variables.

Now I have created two questions for these two variables, with the following Logic-Equations:

[RANDOM]:

{if(RANDOM>=1,RANDOM,rand(1,140))}

[RANDOMTWO]:

{if(RANDOMTWO>=1,RANDOMTWO,
if(RANDOM == 1, rand(2,140),
if(RANDOM == 140, rand(1,139),
if(rand(1,2) == 1, rand(1,(RANDOM-1)), rand((RANDOM+1),140)))))}

However, I will come into trouble, if I want to make more unique random variables.

Therefore, my question is:
Is there another way to generate unique random variables?

LimeSurvey Partners
11 months 1 week ago - 11 months 1 week ago #169995
ATTENTION! The code above does not give complete random variables, but a slightly skewed distribution of random variables.

However, I have found a better solution to create two unique random variables:

1) Create three random variables (questions of the type equation), e.g. RANDOM, RANDOMTWO, RANDOMINT in this order.
2) RANDOM gets the equation:
`{if(RANDOM>=1,RANDOM,rand(1,2))}`
3) RANDOMTWO gets the equation:
`{if(RANDOMTWO >=1, RANDOMTWO, rand(1,2))}`
4) RANDOMINT gets the equation:
`{RANDOMTWO=(if(RANDOMTWO==RANDOM, rand(1,2), RANDOMTWO))}`
--- to increase uniqueness you simply repeat this formula in the equation like this:
`{RANDOMTWO=(if(RANDOMTWO==RANDOM, rand(1,2), RANDOMTWO))} {RANDOMTWO=(if(RANDOMTWO==RANDOM, rand(1,2), RANDOMTWO))} {RANDOMTWO=(if(RANDOMTWO==RANDOM, rand(1,2), RANDOMTWO))} {RANDOMTWO=(if(RANDOMTWO==RANDOM, rand(1,2), RANDOMTWO))}`
Last edit: 11 months 1 week ago by DVP17lemon.

11 months 1 week ago #170026 by mado88
Hi,
This comes close to my problem: A complex survey structure with multiple randomizations within one project. I will try to decribe it. Basically, I would like to run three experiments within one survey.
- Experiment 1 requires random assignment to three groups (A,B,C) (I understand how this works in general)
- Experiment 2 splits each of the three groups in 2 subgroups (i.e. Respondents first assigned to group A will randomly be assigned into group A.1 or A2 for the second question, original group B -> B.1, B.2, original group C-> C.1, C.2)
- Experiment 3 requires a new round of random assignment into 6 groups (U, V, W, X, Y, Z). The former group assignments should not influence this procedure.
- The survey should also have a general part, which everyone answers

I know that it is quite complicated, but do you think it is possible at all with Limesurvey? Thanks a lot!

11 months 1 week ago #170030 by holch
I don't think that it is too complicated, because you actually only have to run 2 random assignments from what I see.
First random assignment generates a number from 1-6.
1 = A1
2 = A2
3 = B1
4 = B2
5 = C1
6 = C2
First assignment: Just show the A questions for those that received 1 and 2, B questions to those that received 3 and 4, etc.
Second assignment: Se above.
3rd assignment: just generate a new random number in a different equation question like before.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.