Hi everyone
I have a question about random number generation.
I have read in the manual and on the forum that the standard ways to generate random numbers are to use the rand() function in the equation manager, or the Math.random() javascript function.
Recently I came across ‘Chance’ which is a nice alternative method for generating random numbers that is meant to be better than rand() or Math.random() as it is based on Mersenne Twister.
chancejs.com/
I can get chance.js to generate random numbers with ease when I use it outside of lime survey.
For example, the follow code successfully generates a random integer:
Code:
<html>
<head></head>
<body>
<script type="text/javascript" src="https://chancejs.com/chance.min.js" charset="utf-8"></script>
<script type="text/javascript">
alert(chance.integer());
</script>
</body>
</html>
However, I am unable to get chance.js to work with limesurvey.
For example, I created a text display question in limesurvey and then (in source mode) added the following script:
Code:
<script type="text/javascript" src="https://chancejs.com/chance.min.js" charset="utf-8"></script>
<script type="text/javascript">
alert(chance.integer());
</script>
When I then execute the survey, no alert pops up on screen containing the random integer.
I have experimented with various settings to try and get chance.js to generate random numbers from within limesurvey. For example, I have tried various question types (Eg short text instead of text display) and also tried including the chance.js file in the head rather than the body of the HTML (by editing limesurvey templates) but nothing has worked.
As the script will successfully generate random numbers when used outside of limesurvey, but does is not working when used inside limsurvey, I assume there is some sort of interaction going on between limesurvey and chance.js that is causing the problem.
Does anyone have any advice as to how I could overcome this problem so that I can use chance.js rather than rand() or Math.random() to generate random values?
Thanks
David
PS I am using LS 2.05+ on an Apache server.