On 30.01.2017 at 17:29, Andrea Faulds wrote: > Christoph M. Becker wrote: > >> Just a quick idea: >> >> <?php >> >> class PNRG { >> public function __construct($seed = null) {…} >> public function get() {…} >> } > > I've long favoured an API along these lines. One size does not fit all, > you need two APIs for (non-crytographic) random numbers: > - automatically-seeded, non-reproducible numbers (a global function like > rand()) > - manually-seeded, reproducible number sequences (objects) > > Currently we mix these two, and it's a mess. The easy solution would be > a random number-generating object like you propose, to cover the second > use-case. We could also introduce a non-manually-seedable global PRNG > also, if desired. Perhaps as a static method of that class. > > One thought: it'd be nice if you had two different methods, one that > mutates in places, and one that doesn't, i.e.: > > $prng1 = new PRNG(SEED); > [$randomNumber, $prng2] = $prng2->getWithNewPRNG(); > > v.s.: > > $prng = new PRNG(SEED); > $randomNumber = $prng->get(); > $randomNumber2 = $prng->get();
Thanks, Andrea! I like all your suggestions, and I'd be happy to see a respective RFC – unfortunately, I won't have time to do this myself in the near future. -- Christoph M. Becker -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php