Randomizing the Order of Questions

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Randomizing the Order of Questions

Post by Gregory Martin »

In CSPro there is no simple way to change the order that questions are asked in a data entry application, but it can be done with some logic. The following code is an example of how one can use logic to randomize the order that questions are asked. The code randomizes the order in which five questions, the field names of which are listed in the fieldNames array, are asked.
PROC GLOBAL

numeric numQuestions = 5;
array questionOrder(5);

array alpha fieldNames(5) = "QUESTION1","QUESTION2","QUESTION3","QUESTION4","QUESTION5";
alpha fieldName;

function gotoQuestion(questionNumber)
    fieldName = fieldNames(questionNumber);
    
move to fieldName;
end;

function nextQuestion()

    fieldName =
getsymbol();

    
// see where we are in the list
    numeric i;
    
    
do i = 1 while fieldNames(i) <> fieldName
    
enddo;

    
// now i points to what question number we're on
    
    
// now find out where in the order it is
    numeric j;

    
do j = 1 while questionOrder(j) <> i
    
enddo;

    
if j = numQuestions then
        
move to ANOTHER_QUESTION; // we are done with the rotating questions

    
else
        gotoQuestion(questionOrder(j +
1));

    
endif;

end;

function startQuestions()

    
numeric i,j;
    
    
do i = 1 while i <= numQuestions
    
        questionOrder(i) =
random(1,numQuestions);
        
        
// see if this question has already been inserted
        do j = ( i - 1 ) while j > 0 by (-1)
            
if questionOrder(j) = questionOrder(i) then // the new value is a repeat
                j = 0; // this will terminate the inner do loop
                i = i - 1; // this will force the outer do loop to repeat for this value
            endif;      
        
enddo;  

    
enddo;
    
    gotoQuestion(questionOrder(
1));

end;

PROC CHANGEQUESTIONORDER_FF

preproc

seed(systime());

PROC CHANGEQUESTIONORDER_ID

startQuestions();

PROC QUESTION1

nextQuestion();

PROC QUESTION2

nextQuestion();

PROC QUESTION3

nextQuestion();

PROC QUESTION4

nextQuestion();

PROC QUESTION5

nextQuestion();
dayom4real
Posts: 4
Joined: August 23rd, 2017, 5:24 pm

Re: Randomizing the Order of Questions

Post by dayom4real »

Hi

I am trying to randomize order of some questions in CSPRO but this is not working. Please can you be more simplify with your codes, I keep receiving buch of errors. Is there anything I must ensure to run the code

I have 3 pair of questions, I want to randomize each pair. in a total I have 6. but each pair is randomized. for example I have Q3A, Q3B, Q4A, Q4B, Q5A, Q5B. when Q3A and Q3B must be randomized together, Q4A and Q4B must also be randomized together and the same goes to Q6A and Q6B.


Please any help will be really apppreciated. Our project is stalked because of this.

Thanks.
juan pablo
Posts: 30
Joined: July 27th, 2017, 4:02 pm

Re: Randomizing the Order of Questions

Post by juan pablo »

hello GREGORY

I've tried logic to randomize the questions like the example that
in operator controlled mode it works very well, in my case I want to use it in system control mode and that's where the errors come up.
Is there any way to use the aleotorizar logic in system control mode?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Randomizing the Order of Questions

Post by Gregory Martin »

I think that you'll have problems with this in system controlled mode. CSPro does not make this task easy.

One other option, assuming that the response options for your questions are the same, is to have a repeating item in the dictionary that you will use to ask several questions. Then, you could modify the CAPI text randomly based on the occurrence of this item. You would also have to save to the data file the order that you asked the questions.
juan pablo
Posts: 30
Joined: July 27th, 2017, 4:02 pm

Re: Randomizing the Order of Questions

Post by juan pablo »

I do not understand very well what he mentions.
so far what I did is duplicate the variables twice to be able to randomize some questions, example
I have my variable P1, P2, P3. I create other variables with the names
  ROTAR
  P1_TMP1,
  P2_TMP1,
  P3_TMP1
  P1_TMP2,
  P2_TMP2,
  P3_TMP2

My logic is for variable ROTAR =
  PREPROC

if visualvalue ($) = NOTAPPL then
  $ = Random (1,13);
ENDIF;
NOINPUT;

My logic for P1_TMP1 =
PREPROC

//******************RANDOM*************

IF ROTAR = 2 THEN SKIP P2_TMP1 ENDIF;
IF ROTAR = 3 THEN SKIP P3_TMP1 ENDIF;

According to the rotation that comes out, it makes the jump in the variables that are repeated TMP and then in the original variables p1, p2 p3 pull the responses of the variables
TMP
pngugi
Posts: 4
Joined: July 26th, 2018, 3:26 pm

Re: Randomizing the Order of Questions

Post by pngugi »

Gregory Martin wrote:I think that you'll have problems with this in system controlled mode. CSPro does not make this task easy.

One other option, assuming that the response options for your questions are the same, is to have a repeating item in the dictionary that you will use to ask several questions. Then, you could modify the CAPI text randomly based on the occurrence of this item. You would also have to save to the data file the order that you asked the questions.

Hi Gregory,

Is it possible for you to create an example of one question illustrating how to randomly display the CAPI text in system control mode? I have tried to create some logic that randomizes the CAPI text in question but I don't seem to get it right.

Kind regards,

Paul
ivilela
Posts: 2
Joined: November 8th, 2021, 12:33 pm

Re: Randomizing the Order of Questions

Post by ivilela »

Hi Gregory,
I am trying to do something similar but I need to randomize the order of a group of forms, instead of questions. Should this also work?
thanks
Ines
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: Randomizing the Order of Questions

Post by aaronw »

I believe Greg's solution is meant for operator control mode. However, I would recommend system control for a CAPI application. I don't think there is a perfect solution for randomizing questions/forms.

If I was working on a project where this was a requirement, I would explore splitting the forms into multiple applications. Randomly launching different applications would be straightforward. However, there would be more design/logic overhead with multiple applications.
ivilela
Posts: 2
Joined: November 8th, 2021, 12:33 pm

Re: Randomizing the Order of Questions

Post by ivilela »

thanks!
Post Reply