note 93079 added to function.openssl-random-pseudo-bytes

From: Date: Fri, 21 Aug 2009 22:18:45 +0000
Subject: note 93079 added to function.openssl-random-pseudo-bytes
Groups: php.notes 
Request: Send a blank email to php-notes+get-159774@lists.php.net to get a copy of this message
Here's a drop-in replacement for rand() using OpenSSL as your PRNG: <?php function crypto_rand($min,$max) { $range = $max - $min; if ($range == 0) return $min; // not so random... $length = (int) (log($range,2) / 8) + 1; return $min + (hexdec(bin2hex(openssl_random_pseudo_bytes($length,$s))) % $range); } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 72.204.204.169 ---- Manual Page -- http://www.php.net/manual/en/function.openssl-random-pseudo-bytes.php Edit -- https://master.php.net/note/edit/93079 Del: integrated -- https://master.php.net/note/delete/93079/integrated Del: useless -- https://master.php.net/note/delete/93079/useless Del: bad code -- https://master.php.net/note/delete/93079/bad+code Del: spam -- https://master.php.net/note/delete/93079/spam Del: non-english -- https://master.php.net/note/delete/93079/non-english Del: in docs -- https://master.php.net/note/delete/93079/in+docs Del: other reasons-- https://master.php.net/note/delete/93079 Reject -- https://master.php.net/note/reject/93079 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159774) next »