# Pre RFC - Additions to the randomizer

- Thread: https://externals.io/message/118762
- Original archive: https://news-web.php.net/php.internals/118762
- Started by Joshua Rüsweg via internals on 2022-10-05T21:44:28+00:00
- Messages: 3
- RFC: Randomizer Additions (Implemented (PHP 8.3)) — https://externals.io/rfc/randomizer_additions.md
- RFC: Random Extension Improvement (Implemented (PHP 8.2)) — https://externals.io/rfc/random_extension_improvement.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #118762 — Joshua Rüsweg via internals — 2022-10-05T21:44:28+00:00

URL: https://externals.io/message/118762#118762

Hi

I would like to introduce a new method for the new Randomizer class [1]. 
I would like to have a function that generates a random string for me 
based on a given alphabet. This function is useful as a building block, 
as many use cases require generating random strings with a specified 
list of characters (e.g. random passwords, voucher codes, numeric 
strings larger than integers) and implementing this in userland requires 
multiple lines of code for what effectively is a very simple operation. 
Furthermore the obvious implementation based on ->getInt() is 
inefficient, as it requires at least one call to the engine per 
character, whereas a 64 Bit engine could generate randomness for 8 
characters at once.

I have opened a Pull-Request on PHP to demonstrate the implementation 
[2] but I am unsure about the method name and decided for 
`getBytesFromAlphabet()` but I am open for better suggestions.

During code review Go Kudo requested that this goes through an RFC and 
Tim Düsterhus requested to handle multiple new methods in bulk. Tim 
implemented a new method, which returns a random float value [3], since 
that's non-trivial to do in userland and an equally useful building 
block like my introduced method.

Since the class into which this function is built is final anyway, the 
methods can be built in with full backwards compatibility.

I look forward to feedback from you!

[1] https://wiki.php.net/rfc/random_extension_improvement
[2] https://github.com/php/php-src/pull/9664
[3] https://github.com/php/php-src/pull/9679

PS: Since this is my first contribution, someone needs to give me karma 
to open an RFC. My account name is `josh`.

Cheers

Joshua Rüsweg

---

## #118781 — Christoph M. Becker — 2022-10-07T15:50:29+00:00

URL: https://externals.io/message/118762#118781 · In reply to: #118762

> PS: Since this is my first contribution, someone needs to give me karma
> to open an RFC. My account name is `josh`.

RFC karma granted.  Best of luck with the RFC!

--
Christoph M. Becker

---

## #118917 — Go Kudo — 2022-10-30T12:28:42+00:00

URL: https://externals.io/message/118762#118917 · In reply to: #118762

2022年10月6日(木) 6:44 Joshua Rüsweg via internals <internals@lists.php.net>:

> Hi
>
> I would like to introduce a new method for the new Randomizer class [1].
> I would like to have a function that generates a random string for me
> based on a given alphabet. This function is useful as a building block,
> as many use cases require generating random strings with a specified
> list of characters (e.g. random passwords, voucher codes, numeric
> strings larger than integers) and implementing this in userland requires
> multiple lines of code for what effectively is a very simple operation.
> Furthermore the obvious implementation based on ->getInt() is
> inefficient, as it requires at least one call to the engine per
> character, whereas a 64 Bit engine could generate randomness for 8
> characters at once.
>
> I have opened a Pull-Request on PHP to demonstrate the implementation
> [2] but I am unsure about the method name and decided for
> `getBytesFromAlphabet()` but I am open for better suggestions.
>
> During code review Go Kudo requested that this goes through an RFC and
> Tim Düsterhus requested to handle multiple new methods in bulk. Tim
> implemented a new method, which returns a random float value [3], since
> that's non-trivial to do in userland and an equally useful building
> block like my introduced method.
>
> Since the class into which this function is built is final anyway, the
> methods can be built in with full backwards compatibility.
>
> I look forward to feedback from you!
>
> [1] https://wiki.php.net/rfc/random_extension_improvement
> [2] https://github.com/php/php-src/pull/9664
> [3] https://github.com/php/php-src/pull/9679
>
> PS: Since this is my first contribution, someone needs to give me karma
> to open an RFC. My account name is `josh`.
>
> Cheers
>
> Joshua Rüsweg
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php
>
>
Hi

I have read the RFC. I think the content is generally good and adequately
compensates for the areas that could not be completed.

I am skeptical only about getFloat(). The use cases are limited and seem
somewhat excessive. Do you have examples of how this is supported in other
languages?

Regards
Go Kudo

P.S.
It's been too long and I had forgotten everything about how to use ML.
Apologies for replying directly to you.
