Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Choose 2 Random Options In Multiple Question

  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 4 weeks ago #257616 by Mon2016
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
(Write here your question/remark)Hello again,

Sorry for asking the question from my previous topic again, but I had to create an account since it no longer allowed me to attach my files or anything.

And it didn't let me log into my account anymore :(
I am writing my question again and sharing the LSS survey with you.

I hope I don't bother anyone.





Hello dear forum,

I am creating a survey where I show a list of coffee shops in a multiple choice question with 8 options.

What I'm trying to do is take 2 random brands from this list if more than 1 brand was selected, that is:

If you select only 1 option, I only ask one question for that selected option.

If you select 2 options, I will ask my next two questions, for those two selected options.

But if you select more than 2 options, for example:

1
3
4
5
7
8

I must take 2 random marks from those 8 options.

What I did is a mark calculation with the equation
join(if(P0401_1 == "Y", "A", ""), if(P0401_2 == "Y", "B", ""), if(P0401_3 == "Y", "C", " "), if(P0401_4 == "Y", "D", ""), if(P0401_5 == "Y", "E", ""), if(P0401_6 == "Y", "F", ""), if(P0401_7 == "Y", "G", ""), if(P0401_8 == "Y", "H", ""))

And then take a random one that works well, but I've gotten stuck trying to figure out how to do it with 2 random ones.

I hope I have been clear, my English is not very good.

My Version 5.6.42+231024

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 4 weeks ago #257618 by Joffm
The next step is to remove the selected character from the string (function "str_replace")
Then the same procedure a second time.
Create a random number from 1 to length of string.
Pick the character at this position.

Quick reply from phone.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 4 weeks ago #257620 by Mon2016
Replied by Mon2016 on topic Choose 2 Random Options In Multiple Question
Thanks Joffm

My first variable where I use the join is:
"eqBrands"
{join(if(P0401_1=="Y","A",""), if(P0401_2=="Y","B",""), if(P0401_3=="Y","C", ""), if(P0401_4=="Y","D",""), if(P0401_5=="Y","E",""), if(P0401_6=="Y","F" ""), if(P0401_7=="Y","G",""), if(P0401_8=="Y","H",""))}


My second variable for the rotation
is:
"eqRand"
if(is_empty(eqRand), rand(1, strlen(eqBrands)), eqRand)


The third variable takes the random mark is:
"eqBrand"
substr(eqBrands, eqRand - 1, 1)

And the fourth is where do I replace the selected brand?
"eqBrands2"
str_replace(eqRand, "", eqBrands)


This is correct?

Thanks for your help. :)

My survey on LSS is going again

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 4 weeks ago #257622 by Joffm
No,
as you read in the manual the syntax is
str_replace(search, replace, subject)

What do you search for? Of course the character you extracted in the previous step: eqBrand
You replace with "nothing"
subject is: eqBrands

Meaning: {str_replace(eqBrand,"",eqBrands)}

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 4 weeks ago #257625 by Mon2016
Replied by Mon2016 on topic Choose 2 Random Options In Multiple Question
Thanks Joffm,

I understand that this replaces the code that has been created randomly and a new random calculation is performed.

Should I create the same variables from the beginning again?

Sorry for the questions but I'm a little new to LS and I still don't fully understand the manual

Please Log in to join the conversation.

  • Mon2016
  • Mon2016's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 4 weeks ago #257626 by Mon2016
Replied by Mon2016 on topic Choose 2 Random Options In Multiple Question
Hello Joffm,

I already solved it, I just repeated the same sequence of variables and everything works wonderfully.

Thank you very much for your help,

Greetings,

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose