Welcome to the LimeSurvey Community Forum

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

Search Results (Searched for: random)

  • Maddie.Storm
  • Maddie.Storm's Avatar
15 Apr 2024 15:42
Replied by Maddie.Storm on topic Randomization 50:50
Sorry, accidentally replied with the wrong account if there was confusion.

Here it is again. 
Thanks.
  • PabloSantos
  • PabloSantos's Avatar
15 Apr 2024 15:34 - 15 Apr 2024 15:44
Replied by PabloSantos on topic Randomization 50:50
Hi!
I am so sorry about that. I attached the lss file here if you want to take a look! It should work.
 
  • rajkumar_dms
  • rajkumar_dms's Avatar
15 Apr 2024 13:06
I aware of the array filter that will show only the selected answer in previous selected answer
But my concern is it will show the randomly only top 3
Can you help on this by custom java script
  • Mazi
  • Mazi's Avatar
15 Apr 2024 12:54
Sounds tricky!
I think a solution can be to use array filter feature to only show the selected items at Q2.
Q2 should be set to be ordered randomly.
You can then apply some custom JS to remove all items after the top three.
  • rajkumar_dms
  • rajkumar_dms's Avatar
15 Apr 2024 08:17 - 15 Apr 2024 08:18
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.5
Own server or LimeSurvey hosting:Cloud
Survey theme/template:
==================
Hello Team,
Good day!
I would like create the random number on basis selected answer of previous question and then only top 3 will selected form that list

For example
I have a question Q1(Multiple choice) having answer option A,B,C,D,E,F,G,H,I AND i have selected option A,C,D,F,G,H,I, for another question Q2(Multiple choice) having same option as Q1 but i need to show the only top 3 option by randomly from Q1

 
  • Joffm
  • Joffm's Avatar
14 Apr 2024 02:11
Replied by Joffm on topic Randomization 50:50
Please provide neither lsq nor lsg exports.
We always ask for lss exports of the relevant questions.

Reason:
lsq and lsg exports are language sensitive.
You can't import them into a survey with a different base language 
So first we have to guess the base language, create a survey to be able to import.
Furthermore your survey wide settings are missing.

lss exports we only have to import.

Please, ease the work of us volunteers.

Joffm
  • Maddie.Storm
  • Maddie.Storm's Avatar
13 Apr 2024 23:42
Replied by Maddie.Storm on topic Randomization 50:50
Sure thing!
Here is the question group attached.

Thank you SO much.
  • Joffm
  • Joffm's Avatar
13 Apr 2024 20:55 - 13 Apr 2024 21:25
Replied by Joffm on topic Randomization 50:50
Better you attach the lss export of your try.

As @holch wrote you create the random number in a question of type "equation" which is called "randnumber". 
Please read the manual about question types.
 Then you enter the shown logical terms (randnumber==1 resp  randnumber==2) in the "condition" field of the question.

And why don't you see a 50:50 distribution?
What do you expect if you throw a coin 100 times? This is analogue to the creation of a random number from 1-2 100 times.

Again my advice. Read the manual, study the included sample surveys to learn the basics about questions, about ExpressionScript, about the implemented functions, etc.

Joffm
  • Maddie.Storm
  • Maddie.Storm's Avatar
13 Apr 2024 18:30
Replied by Maddie.Storm on topic Randomization 50:50
Hi!
I attached pictures here... I know it seems like a mess! 
Would you be able to provide me the exact code to put in these? I am not the best at this.. I am just looking for 50:50 between variables 1 and 2. 
What would be the exact condition for my first question (variable 1) in the group and second question (variable 2)? It does not seem to pick up on randnumber == 1?
Then I tried filling them in and it doesn't seem to work either.

Each Condition for ModifiedGMSEX (1) and FullyModifiedGMSEX (2): ?

Exact Group Relevance Code (Modified GMSEX): ?

Randomization group name: ?


Thank you so much for your help! 
  • Joffm
  • Joffm's Avatar
13 Apr 2024 16:09
Replied by Joffm on topic Randomization 50:50
Hi,
it seems you are confused about it.

You see the construct we use
Code:
{if(is_empty(randnumber), rand(1,2),randnumber)}
Meaning: if "randnumber" is still empty, create a random number from 1-2, otherwise keep it as it is.

Reason for this construct:
If you only use {rand(1,2)} you create a random number. But if the respondent goes back to this question or even group there will be generated a new random number that may be different.
Therefore the check "is_empty". 
​​​​​​

Well, now yoa have in your variable "randnumber" a value (1 or 2).

And now the conditions of your questions.
One question is only displayed if this "randnumber" is equal 1, the other if it is equal 2.

And exactly this you enter into the condition of the question.
randnumber==1 resp. randnumber==2

Best you read the manual, "ExpressionScript" again and you may download and import the sample surveys provided in the manual.

Joffm 
  • Maddie.Storm
  • Maddie.Storm's Avatar
13 Apr 2024 15:42
Replied by Maddie.Storm on topic Randomization 50:50
Hi! Thank you so much for responding. I just tried to do it, but I think I still have a problem. My questions are in array form and they have to stay that way. It is for the scale validity in our study, and it seems like the equation style would not work for the length and look of the array.
So, is there any way to randomize arrays 50:50? Is there a code for these? Where do I put each code?

Also, how do I do this: "You need to check if this random number already exists before you create it new."? How do I assign one question as 1 and the other as 2? Does this go into the condition box?

Thanks so much! I am very new to LimeSurvey. 
  • tpartner
  • tpartner's Avatar
12 Apr 2024 14:06
This should do it:

Code:
<script type="text/javascript">
    $(document).on('ready pjax:scriptcomplete',function(){
 
        function shuffleArray(array) {
            for (var i = array.length - 1; i > 0; i--) {
                var j = Math.floor(Math.random() * (i + 1));
                var temp = array[i];
                array[i] = array[j];
                array[j] = temp;
            }
            return array;
        }
 
        // Merge function
        function mergeArrays(array1, array2) {
            var mergedArray = [];
            var maxLength = Math.max(array1.length, array2.length);
 
            for (var i = 0; i < maxLength; i++) {
                if (i < array2.length) {
                    mergedArray.push(array2[i]);
                }
                if (i < array1.length) {
                    mergedArray.push(array1[i]);
                }
            }
 
            return mergedArray;
        }
 
        //Identify this question
        var thisQuestion = $('#question{QID}');
        var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent();
        var thisTable = $('table.subquestion-list:eq(0)', thisQuestion);
 
        // Special codes appear after
        var afterCode = 4;
 
        //Array for K Codes
        var array_k = ["b","d","g","h","i","j","l"];
 
        //Array for N Codes
        var array_n = ["c","e","f","k","m","n"];
 
        //Array for Special K Codes
        var array_sk = [];
 
        //Array for Special N codes
        var array_sn = ["a"];
 
        //Array for super special codes
        var array_ss = ["p"];
 
        // Shuffle order of "normal" arrays
        shuffleArray(array_k);
        shuffleArray(array_n);
 
        // Slice "normal" arrays and merge second part to special codes
        array_sk = array_sk.concat(array_k.slice(afterCode));
        array_sn = array_sn.concat(array_n.slice(afterCode));
 
        // Save only first part of "normal" arrays
        array_k = array_k.slice(0, afterCode);
        array_n = array_n.slice(0, afterCode);
 
        // Shuffle special arrays
        shuffleArray(array_sk);
        shuffleArray(array_sn);
        shuffleArray(array_ss);
 
        // Combine normal and special arrays
        array_k = array_k.concat(array_sk);
        array_n = array_n.concat(array_sn);
 
        // Merge arrays in order n,k,n,k...
        var array_res = mergeArrays(array_k, array_n);
 
        //Add super special array to end of result array
        array_res = array_res.concat(array_ss);
 
        // Loop through the answer codes
        $.each(array_res, function(i, val) {
            // Move the answer item
            $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
        });
 
        // Fix up the row background colours
        $('tr.answers-list', thisQuestion). each (function(i){
            $(this).removeClass('ls-even ls-odd');
            if(i % 2 == 0) {
                $(this).addClass('ls-even');
            }
            else {
                $(this).addClass('ls-odd');
            }
        });
 
    });  
 
</script>

Sample survey: 

File Attachment:

File Name: limesurvey...3181.lss
File Size:41 KB
  • holch
  • holch's Avatar
11 Apr 2024 22:36
Replied by holch on topic Randomisierung auf zwei Ebenen
Genau so funktioniert es.
  • holch
  • holch's Avatar
11 Apr 2024 21:47
Replied by holch on topic Randomization 50:50
Creating a 50/50 chance is easy, there have been many posts about this in the forum. You basically create a random number between 1 and 2 within a equation type question and then use the relevance equation / condition of the question to show / hide it depending on the number that has been drawn.

However, to make sure you don't run into trouble, you shouldn't just create a random number via {rand(1,2)}, but you need to check if this random number already exists, before you create it new.

Why is this important? Because otherwise you are running the risk that the random number changes for the same participant. Because with {rand(1,2)} the "dice are rolled everytime this equation question is called.
Code:
{if(is_empty(randnumber),rand(1,2),randnumber.NAOK)}
  • Maddie.Storm
  • Maddie.Storm's Avatar
11 Apr 2024 18:45
Randomization 50:50 was created by Maddie.Storm
Hi!
I am looking to randomize the Modified GMSEX here and the Fully Modified GMSEX here. When participants get to this stage of the survey, I need it to be 50/50 chance of getting either one. 
How do I do this? Is there a code? If so, where does this go?

Thanks!
Displaying 31 - 45 out of 658 results.

Lime-years ahead

Online-surveys for every purse and purpose