Welcome to the LimeSurvey Community Forum

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

3 random numbers out of 5

  • exlibris69
  • exlibris69's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 6 months ago #127687 by exlibris69
3 random numbers out of 5 was created by exlibris69
Hi guys,

does anybody know how is it possible to display 3 random numbers out of 5 in one (!) equation question? For the moment I use equation which displayes 1 number {if(is_empty(Q1ran),rand(1,5),Q1ran)} and now it should be increased to 3 figures.

Hope somebody can help me.
Thanks in advance.
The topic has been locked.
More
8 years 6 months ago #127697 by first
Replied by first on topic 3 random numbers out of 5
Do you just want to show these number or want to do something with them? . We can suggest something if you can let us know little more what exactly you want to achieve in survey.

Survey Designer and Programmer
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 6 months ago #127698 by tpartner
Replied by tpartner on topic 3 random numbers out of 5
I'm not sure you can do that in one equation question but using JavaScript, you could load three sub-questions of a multiple-short-text question with 3 random numbers out of 5.

Set up your survey to use JavaScript and add the following script to the source of a multiple-short-text question (I think the comments explain what's happening):

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Hide this question (un-comment below)
    //thisQuestion.hide();
 
    var numbers = [1,2,3,4,5];    
 
    // A function to shuffle elements or contents of arrays
    (function($){
      $.fn.shuffle = function() {
        return this.each(function(){
          var items = $(this).children();
          return (items.length)
            ? $(this).html($.shuffle(items))
            : this;
        });
      }
 
      $.shuffle = function(arr) {
        for(
          var j, x, i = arr.length; i;
          j = parseInt(Math.random() * i),
          x = arr[--i], arr[i] = arr[j], arr[j] = x
        );
        return arr;
 
      }
    })(jQuery);
 
    // Shuffle the array
    numbers = $.shuffle(numbers);
 
    //Load the first three array values and fire Expression Manager
    $('input.text', thisQuestion).each(function(i) {
      $(this).val(numbers[i]);
      checkconditions(this.value, this.name, this.type);
    });
  });
</script>

Sample question attached:

File Attachment:

File Name: limesurvey...5010.lsq
File Size:4 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • exlibris69
  • exlibris69's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 6 months ago #127701 by exlibris69
Replied by exlibris69 on topic 3 random numbers out of 5
For the moment we have a question of products categories consumption. There are 5 categories, which should be evaluated. Each category has block of nearly 20 questions. Respondent can chose up to 5 categories. In case the respondent chose 4 or 5 product categories he should evaluate 3 of categories he knows randomly. Now it's a problem to prescribe conditions for all groups of respondents - to be exact, for those who chose up to 3 cat. and should evaluate all 3 and for those who chose 4+ and should evaluate randomly 3 of 4 or 5.
The topic has been locked.
More
8 years 6 months ago #127717 by first
Replied by first on topic 3 random numbers out of 5
x= max number of products to rate.
hq = hidden multi question;

steps:
#Copy punches in hq using EM.
#Randomize answer list of hq.
#Keep top x and clean all other using javascript
#Use hq in array mask of desired question.

LSS :

File Attachment:

File Name: limesurvey...47-2.lss
File Size:23 KB

Survey Designer and Programmer
The topic has been locked.
  • exlibris69
  • exlibris69's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 6 months ago #127718 by exlibris69
Replied by exlibris69 on topic 3 random numbers out of 5
Thank you a lot. I've found this solution in Lime manual. :)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose