Hi, asmusaj,
at first: Why didn't you answer the initial questions?
herefore, rand() does not work.
Of course it does.
There are several options.
1. Your ranges cover 214 possible numbers.
a. Create a random number (r1) form 1-214:
{if(is_empty(r1),rand(1,214),r1)}
b. Create your final random number (r2) in a nested IF-function :
{if(r1<52,r1+849,if(r1<83,r1+908,if(r1<114,r1+927,r1+986)))}
In my opinion it is the best one.
2. Use a random number to define the range and a second to get the final number
a. create a random number from 1-4 (r3):
{if(is_empty(r3),rand(1,4),r3)}
b. create your final random number (r4) in again in a nested IF:
{if(r3==1,if(is_empty(r4),rand(850,900),r4),if(r3==2,if(is_empty(r4),rand(960,990),r4),if(r3=
,if(is_empty(r4),rand(1010,1040),r4),if(is_empty(r4),rand(1100,1200),r4))))}
3. Solution with javascript
create a question of type "short text" and enter the following script in source code mode
Code:
<script type="text/javascript" charset="utf-8">
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
$(document).on('ready pjax:scriptcomplete',function(){
// Fill the array
var arr = [];
for (var i = 850; i < 901; i++) {
arr.push(i);
}
for (var i = 960; i < 991; i++) {
arr.push(i);
}
for (var i = 1010; i < 1041; i++) {
arr.push(i);
}
for (var i = 1100; i < 1201; i++) {
arr.push(i);
}
arr = shuffle(arr);
anumbers = arr.slice(0,1).join('');
$('#question{QID} input[type="text"]').val(anumbers);
// After testing remove the slashes to hide the question
// $('#question{QID}').hide();
});
</script>
Joffm