- Posts: 24
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Randomisation using PHP 7.0 or above
- gorp
- Topic Author
- Offline
- Junior Member
Less
More
4 years 1 month ago #194768
by gorp
Randomisation using PHP 7.0 or above was created by gorp
Hi,
I've used rand() like below in an equation question to get a random number or 1 or 2. This works fine:
{if(is_empty(condition1),rand(1,2),condition1)} .
However, I would now like to use random_int, but when I do that it says Undefined function even though the website is using PHP 7.0. This is what I now have.
{if(is_empty(condition1),random_int(1,2),condition1)}
Can someone please help?
I've used rand() like below in an equation question to get a random number or 1 or 2. This works fine:
{if(is_empty(condition1),rand(1,2),condition1)} .
However, I would now like to use random_int, but when I do that it says Undefined function even though the website is using PHP 7.0. This is what I now have.
{if(is_empty(condition1),random_int(1,2),condition1)}
Can someone please help?
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
4 years 1 month ago #194769
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Randomisation using PHP 7.0 or above
Please, read the manual about implemented functions
manual.limesurvey.org/Expression_Manager#Implemented_Functions
Joffm
manual.limesurvey.org/Expression_Manager#Implemented_Functions
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
4 years 1 month ago #194774
by jelo
github.com/LimeSurvey/LimeSurvey/blob/26...s/em_core_helper.php
If you want to use random_int, you would need to submit a feature request or modify the LimeSurvey code.
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic Randomisation using PHP 7.0 or above
The ExpressionScript/ExpressionManager functions are using PHP functions, but not exposing all functions of PHP.gorp wrote: However, I would now like to use random_int, but when I do that it says Undefined function even though the website is using PHP 7.0.
github.com/LimeSurvey/LimeSurvey/blob/26...s/em_core_helper.php
If you want to use random_int, you would need to submit a feature request or modify the LimeSurvey code.
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
4 years 1 month ago #194776
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Randomisation using PHP 7.0 or above
Well,
without having to hack the core, you may create a question of type short text and do an ajax call.
Like this:
And in the called php script you grab "min" and "max" and echo random_int(min,max);.
Just an idea.
Joffm
without having to hack the core, you may create a question of type short text and do an ajax call.
Like this:
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ $.post('https://www.myServer/getRandom.php' ,{ min: "[minValue]", max: "[maxValue]"} function(data) { $('#question{QID} input[type="text"]').val(data) }); // $('#question{QID}').hide(); }); </script>
And in the called php script you grab "min" and "max" and echo random_int(min,max);.
Just an idea.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 years 1 month ago #194782
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Randomisation using PHP 7.0 or above
Or use chance.js -
chancejs.com/
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13648
- Thank you received: 2491
4 years 1 month ago #194838
by DenisChenu
Not if you use 4.X : manual.limesurvey.org/ExpressionManagerStart
See this sample : github.com/LimeSurvey/LimeSurvey/tree/ma...mo/demoAddEmFunction
And since random_int is a PHP function, you can set the function as "static" : see github.com/LimeSurvey/LimeSurvey/tree/ma...lugins/statFunctions
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Randomisation using PHP 7.0 or above
No,jelo wrote: ....
If you want to use random_int, you would need to submit a feature request or modify the LimeSurvey code.
Not if you use 4.X : manual.limesurvey.org/ExpressionManagerStart
See this sample : github.com/LimeSurvey/LimeSurvey/tree/ma...mo/demoAddEmFunction
And since random_int is a PHP function, you can set the function as "static" : see github.com/LimeSurvey/LimeSurvey/tree/ma...lugins/statFunctions
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.