# Randomnumber based variables

4 years 5 months ago #110450
tischer_s created the topic: Randomnumber based variables
Hi,

In my survey I have 16 treatments which are randomized via a rand(1;16) function.

Now I want to implement two hidden questions containing of the independant changed variables which are filled with numbers based on the random number.

In each treatment either the storage and/or the price is changed.

Here some examples:

Rand 1 -> storage: 2GB ; price: 0€
Rand 2 -> storage: 2GB ; price: 9,99€
Rand 3 -> storage: 2GB ; price: 19,99€

Now I want the variable price and storage and they should be hidden for the users but fill with numbers based on the values shown.

Rand 1 -> storage: 2 ; price: 0
Rand 2 -> storage: 2 ; price: 9,99
Rand 3 -> storage: 2 ; price: 19,99

Something like:

If randnumber=2, storag=2; price=9,99

This is no function but should cover what I want.

Best

Sebastian Tischer

4 years 5 months ago - 4 years 5 months ago #110467
DenisChenu replied the topic: Randomnumber based variables
Hi,

Don't really understand your need here.

But you can use Equation question type and EM.

1st question RANDOM : {rand(1,3)}
Equation hidden question : {if(RANDOM== "1" or RANDOM== "2" or RANDOM== "3",2,"")}

etc ....
You can use one Equation question type and Assign a answer:
{ANDWER=if(RANDOM== "1" or RANDOM== "2" or RANDOM== "3",2,"")}

See : manual.limesurvey.org/Expression_Manager

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 4 years 5 months ago by DenisChenu. Reason: manual link

4 years 5 months ago #110468
tischer_s replied the topic: Randomnumber based variables
Hi DenisChenu,

I am sorry for not writing it more clearly.

I need to give an value to a variable based on the random number.

My questionnaire starts with a randomnumber generator (rand(1,16)). Then I have treatments which I only show when each randomized number is shown.

randnum 1 -> Treatment 1
randnum 2 -> Treatment 2
...

Each Treatment varies in price and storage. For a better export I want to have two new hidden "questions" where the number and storage of the treatment is in.

Like:

randnum 1 -> price: 0 storage: 2
randnum 2 -> price: 9,99 storage: 2
randnum 3 -> price: 19,99 storage: 2

Your expression is a good start unfortunately I don't know how to set a value as an answer...

{if(RANDOM== "1") then price=="0" and storage=="2"}

Is anything like this even possible?

Best and thank you very much

Sebastian

4 years 5 months ago #110474
DenisChenu replied the topic: Randomnumber based variables

tischer_s wrote: Your expression is a good start unfortunately I don't know how to set a value as an answer...

{if(RANDOM== "1") then price=="0" and storage=="2"}

Is anything like this even possible?

```{price=if(RANDOM== "1",0,1)}
{storage=if(RANDOM== "1",2,1)}```
et ...

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

4 years 5 months ago #110478
tischer_s replied the topic: Randomnumber based variables
Hi DenisChenu,

Thanks a lot for your great help This is exactly what I was searching for!

Only three questions:

1. how can I combine multiple statements like random=="1" and random=="2" etc?
2. what is the second number in the "1",0,1 statement?
3. how can I enter the number 9,99? Do I need a fullstop as separation?

Is this right?
```{price=if(RANDOM== "1",0,1),if(RANDOM=="2",9,99),if(RANDOM=="3",19,99}
{storage=if(RANDOM== "1",2,1)}```

4 years 5 months ago #110479
DenisChenu replied the topic: Randomnumber based variables

manual.limesurvey.org/Expression_Manager
```{price=if(RANDOM== "1",0,
if(RANDOM=="2",9,
if(RANDOM=="3",19,99)
)
)}```

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: tischer_s

4 years 5 months ago - 4 years 5 months ago #110483
tischer_s replied the topic: Randomnumber based variables
Hi again,

I am so sorry for disturbing you. Unfortunately I am not that technical knowledged thats why I am running into some trouble

I entered the following code now into my question field named "price":
```{price=if(randnumber== "1","0",
if(randnumber=="2","9,99",
if(randnumber=="3","19,99",
if(randnumber=="4","49,99",
if(randnumber=="5","0",
if(randnumber=="6","9,99",
if(randnumber=="7","19,99",
if(randnumber=="8","49,99",
if(randnumber=="9","0",
if(randnumber=="10","9,99",
if(randnumber=="11","19,99",
if(randnumber=="12","49,99",
if(randnumber=="13","0",
if(randnumber=="14","9,99",
if(randnumber=="15","19,99",
if(randnumber=="16","49,99"))))))))))))))))}
```

Unfortunately it tells me that there is an extra comma in the function? Am I doing something wrong?

Thank you very much

Best
Sebastian
##### Attachments:
Last Edit: 4 years 5 months ago by tischer_s. Reason: Small typo

4 years 5 months ago #110491
DenisChenu replied the topic: Randomnumber based variables
Because you allways need a 'if false' value.
```{price=if(randnumber== "1","0",
if(randnumber=="2","9,99",
if(randnumber=="3","19,99",
if(randnumber=="4","49,99",
if(randnumber=="5","0",
if(randnumber=="6","9,99",
if(randnumber=="7","19,99",
if(randnumber=="8","49,99",
if(randnumber=="9","0",
if(randnumber=="10","9,99",
if(randnumber=="11","19,99",
if(randnumber=="12","49,99",
if(randnumber=="13","0",
if(randnumber=="14","9,99",
if(randnumber=="15","19,99",
if(randnumber=="16","49,99",""))))))))))))))))}```

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: tischer_s

4 years 5 months ago #110492
tischer_s replied the topic: Randomnumber based variables
Hi again,

thank you sooo very much for your great help! Now the equation is working without errors.

Unfortunately it is not giving me an answer based on the expression?

In my answer panel I get this output not any of the numbers we assigned to the randomnumber

Best

Sebastian
##### Attachments:

4 years 5 months ago #110564
tischer_s replied the topic: Randomnumber based variables
@DenisChenu:

May you please take a last look?

I am stuck with this error message...

Thank you very much for your help.

Best

Sebastian Tischer