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.
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:
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:
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?
Can you provide a test link (little survey with this system (only one question is the best)).
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. -
Professional support
-
Plugins, theme and development
. I don't answer to private message.
You can give a link ? It's speedest for me if you give s directly a link ...
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. -
Professional support
-
Plugins, theme and development
. I don't answer to private message.
Your website is in HTTPS, then your browser (Chrome and FF up to 23) block link to non https javascript content.
Please : sue your browser javascript console to track donc error.
Another thing : it's better for chance dev if you don't use his own website : it's not a public CDN (Developper don't put information like this).
Then: upload the chance.js file to your own website (with https) and use this link.
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. -
Professional support
-
Plugins, theme and development
. I don't answer to private message.
For proper surveys I always use a CDN or upload the external js files to my own server. I’d only linked to the developer site this time around while testing the script. I didn't realise that would be cause errors due to the chance website being insecure.
I changed the script src to a copy of on my own server (over HTTPS) which has resolved the problem.