Edit report at http://pear.php.net/bugs/bug.php?id=16790&edit=1
ID: 16790
Updated by: jmcastagnetto@php.net
Reported By: forum at numericalexample dot com
Summary: functions generating random numbers need array output
as well
-Status: Open
+Status: Bogus
Type: Feature/Change Request
Package: Math_Stats
Operating System: any
Package Version: Unknown
PHP Version: Irrelevant
Roadmap Versions:
New Comment:
-Status: Open
+Status: Bogus
You have submitted the bug to the wrong package. The PEAR Math_Stats
does no
have the function you mention (it only implements basic descriptive
statistics
measurements), it is the stats PHP extension which implements such
functions, see:
http://www.php.net/manual/en/function.stats-rand-gen-funiform.php
Next time, please, do take care to send a bug to the correct
package/mantainer.
Cheers.
Previous Comments:
------------------------------------------------------------------------
[2009-11-15 14:31:54] numericalexample
Description:
------------
The Math/Stats package has many useful functions, such as
stats_rand_gen_funiform. Similar random number functions exist for other
probability distributions.
I have a request for a simple but extremely useful extension of these
random number generating functions. Right now all random generating
functions return just a single integer or float. The extension is that
these functions can also return an array of integers or floats. In that
way PHP can compute random functions in a much more efficient way. Such
arrays of random numbers are extremely useful for doing so called Monte
Carlo simulations.
I have no compiler set up but I mean something along the lines below.
This function should return an array of uniformly distributed random
double precision numbers.
PHP_FUNCTION(stats_rand_gen_array_funiform)
{
double low;
double high;
long n;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddl", &low,
&high, &n) == FAILURE) {
RETURN_FALSE;
}
if (low > high) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "low greater than high.
low : %16.6E high : %16.6E", low, high);
RETURN_FALSE;
}
if (n<0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "array length should be
greater than or equal to zero", n);
RETURN_FALSE;
}
array_init(return_value);
for (int i=0; i<n; i++) {
add_next_index_double(return_value, genunf(low, high));
}
}
------------------------------------------------------------------------