Skip to content

Commit 6903a2a

Browse files
committed
Remove exception in Randomizer::shuffleBytes()
The only way that `php_binary_string_shuffle` fails is when the engine itself fails. With the currently available list of engines we have: - Mt19937 : Infallible. - PcgOneseq128XslRr64: Infallible. - Xoshiro256StarStar : Infallible. - Secure : Practically infallible on modern systems. Exception messages were cleaned up in phpGH-9169. - User : Error when returning an empty string. Error when seriously biased (range() fails). And whatever Throwable the userland developer decides to use. So the existing engines are either infallible or throw an Exception/Error with a high quality message themselves, making this exception not a value-add and possibly confusing.
1 parent 5e518c0 commit 6903a2a

File tree

2 files changed

+0
-11
lines changed

2 files changed

+0
-11
lines changed

ext/random/randomizer.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ PHP_METHOD(Random_Randomizer, shuffleBytes)
215215

216216
RETVAL_STRINGL(ZSTR_VAL(bytes), ZSTR_LEN(bytes));
217217
if (!php_binary_string_shuffle(randomizer->algo, randomizer->status, Z_STRVAL_P(return_value), (zend_long) Z_STRLEN_P(return_value))) {
218-
zend_throw_exception(spl_ce_RuntimeException, "Random number generation failed", 0);
219218
RETURN_THROWS();
220219
}
221220
}

ext/random/tests/03_randomizer/user_unsafe.phpt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,6 @@ Stack trace:
107107
#0 %s(%d): Random\Randomizer->shuffleBytes('foobar')
108108
#1 {main}
109109

110-
Next RuntimeException: Random number generation failed in %s:%d
111-
Stack trace:
112-
#0 %s(%d): Random\Randomizer->shuffleBytes('foobar')
113-
#1 {main}
114-
115110
=====================
116111
HeavilyBiasedEngine
117112
=====================
@@ -149,9 +144,4 @@ Stack trace:
149144
#0 %s(%d): Random\Randomizer->shuffleBytes('foobar')
150145
#1 {main}
151146

152-
Next RuntimeException: Random number generation failed in %s:%d
153-
Stack trace:
154-
#0 %s(%d): Random\Randomizer->shuffleBytes('foobar')
155-
#1 {main}
156-
157147
=====================

0 commit comments

Comments
 (0)