From 8cc80397a853447ccce9e9e3f1d37186b78136f8 Mon Sep 17 00:00:00 2001 From: Sander Bol Date: Sat, 9 Jun 2018 09:49:48 +0200 Subject: [PATCH 1/2] Transition from mt_rand to random_int See: http://php.net/manual/en/function.mt-rand.php ``` Caution This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. If you need a cryptographically secure value, consider using random_int(), random_bytes(), or openssl_random_pseudo_bytes() instead. ``` Of course, this example is not doing anything "cryptographically secure". However, it does seem to make sense to promote using the more secure way of generating random numbers, to nudge people in the right direction if they do start building cryptographically sensitive stuff. --- page_creation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/page_creation.rst b/page_creation.rst index 819cdc270dd..65e0216e877 100644 --- a/page_creation.rst +++ b/page_creation.rst @@ -53,7 +53,7 @@ random) number and prints it. To do that, create a "Controller class" and a { public function number() { - $number = mt_rand(0, 100); + $number = random_int(0, 100); return new Response( 'Lucky number: '.$number.'' @@ -248,7 +248,7 @@ variable so you can use it in Twig:: */ public function number() { - $number = mt_rand(0, 100); + $number = random_int(0, 100); return $this->render('lucky/number.html.twig', array( 'number' => $number, From 33e99415e8d4736f5920a85bbbcb77b8211d3105 Mon Sep 17 00:00:00 2001 From: Sander Bol Date: Sat, 9 Jun 2018 10:00:24 +0200 Subject: [PATCH 2/2] Update controller.rst --- controller.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller.rst b/controller.rst index 5ce2d15415c..ff215ff6385 100644 --- a/controller.rst +++ b/controller.rst @@ -38,7 +38,7 @@ class:: */ public function number($max) { - $number = mt_rand(0, $max); + $number = random_int(0, $max); return new Response( 'Lucky number: '.$number.''