More powerful (and backward compatible) API of random number generator functions
| From: | Marc Bennewitz | Date: | Wed, 28 Aug 2013 20:59:34 +0000 |
| Subject: | More powerful (and backward compatible) API of random number generator functions | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-68651@lists.php.net to get a copy of this message | ||
Idea for an RFC for a more powerful (and backward compatible) API of
random number generator functions.
The following psaudocode is self explained (hopfully)
const RAND_ALGO_LIBC
const RAND_ALGO_MERSENNE_TWISTER
const RAND_ALGO_OPENSSL
const RAND_ALGO_GMP
...
// changed functions (added optional $algo argument)
void srand($seed = null, $algo = rand_algo_default())
int rand($min = 0, $max = getrandmax(), $algo = rand_algo_default())
mixed array_rand(array $input, $num_req = 1, $algo = rand_algo_default())
bool shuffle(array &$array, $algo = rand_algo_default())
string str_shuffle(string $str, $algo = rand_algo_default())
// new functions
// set/get the default algo
int rand_algo_default($algo = null)
// get a list of available algos
array rand_algo_list()
// generate random $length bytes
string str_rand($length = 1, $algo = rand_algo_default())
// deprecate functions
mt_srand()
mt_rand()
mt_getrandmax()
openssl_random_pseudo_bytes()
gmp_random()
What do you think?