note 111242 added to function.rand

From: Date: Tue, 29 Jan 2013 22:51:17 +0000
Subject: note 111242 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-193433@lists.php.net to get a copy of this message
The Windows rand() function is quite a lot worse than merely having a low maximum value. It's an ordinary Linear Congruential Generator, which means you only need three consecutive values to be able to predict its entire future output. Given the numbers 13050, 4267, 25352, construct the equations 4267 = (13050a+c) % 32768 25352 = (4267a+c) % 32768 Solving for a and c gives a = 20077 c = 12345 Which means the next number that should be spat out is (25352×20077+12345) % 32768 = 19105 -- which indeed it is. It's not the small rand_max that breaks the algorithm, it's a weakness in the LCG algorithm itself. It's designed for when you only want a few kinda-random numbers occasionally, not if you want to generate any random-looking data. ---- Server IP: 69.147.83.199 Probable Submitter: 122.57.198.66 ---- Manual Page -- http://php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/111242 Del: integrated -- https://master.php.net/note/delete/111242/integrated Del: useless -- https://master.php.net/note/delete/111242/useless Del: bad code -- https://master.php.net/note/delete/111242/bad+code Del: spam -- https://master.php.net/note/delete/111242/spam Del: non-english -- https://master.php.net/note/delete/111242/non-english Del: in docs -- https://master.php.net/note/delete/111242/in+docs Del: other reasons-- https://master.php.net/note/delete/111242 Reject -- https://master.php.net/note/reject/111242 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193433) next »