0 votes
ago in SoSci Survey (English) by s311347 (120 points)

I’m trying to set a deterministic randomization order across four blocks (DS, HPB, MVS, AM) using setPageOrder() in a PHP page (RAND), directly after a Random Generator (B80). The function works only if I start the questionnaire from mid-point, but not from page 1. It seems value('B801') is not yet available when RAND runs. Could you confirm the correct timing or recommend the best practice for this setup?

Here the code:

/* =====================================================
RANDOMIZATION – BASE (ES) with Random Generator B801
===================================================== */

/* 1) Read the generator value 1..24 (Page 06) */
$rg = (int) value('B80'); // <-- B80, without _01
registerVariable($rg);
if ($rg < 1 || $rg > 24) { $rg = mt_rand(1, 24); }

/* 2) Define blocks (IDs of your pages) */
$DS = array('10','11','12','13','14');
$HPB = array('15','16','17','18','19');
$MVS = array('20','21','22','23','24');
$AM = array('25','26','27','28','29');
$TAIL = array('A27','A28','A30'); // without 'end'
$labels = array('DS','HPB','MVS','AM');

/* 3) 24 permutations */
$orders = array(
array(0,1,2,3), array(0,1,3,2), array(0,2,1,3), array(0,2,3,1),
array(0,3,1,2), array(0,3,2,1),
array(1,0,2,3), array(1,0,3,2), array(1,2,0,3), array(1,2,3,0),
array(1,3,0,2), array(1,3,2,0),
array(2,0,1,3), array(2,0,3,1), array(2,1,0,3), array(2,1,3,0),
array(2,3,0,1), array(2,3,1,0),
array(3,0,1,2), array(3,0,2,1), array(3,1,0,2), array(3,1,2,0),
array(3,2,0,1), array(3,2,1,0)
);

/* 4) Build sequence */
$orderIdxs = $orders[$rg - 1];
$blocks = array($DS, $HPB, $MVS, $AM);
$sequence = array();
$labelsOrder = array();
foreach ($orderIdxs as $i) {
$sequence = array_merge($sequence, $blocks[$i]);
$labelsOrder[] = $labels[$i];
}
if (!empty($TAIL)) { $sequence = array_merge($sequence, $TAIL); }
$sequence = array_values(array_unique($sequence));

/* 5) Set the order ONCE and save traces */
setPageOrder($sequence);
put('F301_01', implode('-', $labelsOrder)); // human-readable order
put('F301_02', $rg); // index 1..24
put('F301_03', implode('-', $sequence)); // page IDs in order

/* 6) (Optional during tests) Show the computed order on screen */
// debug('RG=' . $rg . ' | ORDER=' . implode('-', $labelsOrder) . ' | SEQ=' . implode(' > ', $sequence));

1 Answer

0 votes
ago by SoSci Survey (357k points)

What is the reason, you're working with mt_rand()? And are you sure that the variable name of the random generator is "B80"?

It seems that you're using numbers instead of page IDs (that start with a letter)?!

If your goal is to shuffle the order of 4 blocks, 2 lines of PHP code would be sufficient - unless it is important to systematically use each order equally often.

The random generator would the draw 4 out of these four codes (page 11 would have the label "DS_first" here, etc.):

DS_first-DS_last
HPB_first-HPB_last
MVS_first-MVS_last
AM_first-AM-last

The PHP code would be

$blocks = array_values(valueList('B001', null, 'label'));
setPageOrder($blocks);

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...