View Issue Details

This bug affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
12248Feature requestsExpression Managerpublic2019-09-07 10:58
Reporterjelo Assigned To 
PrioritynoneSeverityfeature 
Status newResolutionopen 
Summary12248: Expose php mt_rand to Expression manager
Description

The rand() is not a very good PRNG.
Please add mt_rand to Expression manager.
http://is.php.net/manual/en/function.mt-rand.php

A change of rand() (EM) to use mt_rand (PHP) would be possible too, but might would add compatibility issues when comparing old and new results.

TagsNo tags attached.
Bug heat4
Story point estimate
Users affected %

Relationships

related to 15246 closedDenisChenu Allow fixed function (no js, only PHP) in expression mùanager 

Users monitoring this issue

There are no users monitoring this issue.

Activities

DenisChenu

DenisChenu

2017-04-04 00:34

developer   ~43374

7.1.0 rand() has been made an alias of mt_rand().
7.1.0 mt_rand()has been updated to use the fixed, correct, version of the Mersenne Twister algorithm. To fall back to the old behaviour, use mt_srand() with MT_RAND_PHP as the second paramter.

But for js : use Math.random or another ?

jelo

jelo

2017-04-04 09:38

partner   ~43376

Was there a time when rand() was not using PHP?
I still wonder why manual examples stating {floor(rand(1,6.9999))}. The purpose of floor is unclear when rand() output is always integer. The 6.9999 as a parameter for php rand() is not needed.
https://manual.limesurvey.org/Expression_Manager_Sample_Surveys#Randomly_Ask_One_Question_Per_Group

jelo

jelo

2017-04-04 10:08

partner   ~43378

The rand() JS for rand() PHP was this, right?

function rand (min, max) {
var args = arguments.length;
if (args === 0) {
min = 0;
max = 32768;
}
return Math.floor( Math.random() * (max - min + 1) ) + min;
}

MT implementations for JS are available. But choosing the right one might be a bigger task.

I'm really surprised that no rand() compatibility is maintained for PHP 7.1.
http://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.rand-srand-aliases

Issue History

Date Modified Username Field Change
2017-04-03 12:11 jelo New Issue
2017-04-04 00:34 DenisChenu Note Added: 43374
2017-04-04 09:38 jelo Note Added: 43376
2017-04-04 10:08 jelo Note Added: 43378
2019-09-07 10:58 DenisChenu Relationship added related to 15246