title: Why rand() isn't really random?
body: <p>I wanted to put random points on an image (stars in space for some little fun side project)</p>
  
  <p>I have this simple script. </p>
  
  <pre><code>&lt;?php
  $gd = imagecreatetruecolor(1000, 1000);
  $white = imagecolorallocate($gd, 255, 255, 255);
  
  for ($i = 0; $i &lt; 100000; $i++) 
  {
      $x = rand(1,1000);
      $y = rand(1,1000);
  
      imagesetpixel($gd, round($x),round($y), $white);
  }
  
  header('Content-Type: image/png');
  imagepng($gd);
  ?&gt;
  </code></pre>
  
  <p>Keep in mind this is just for testing, that is why I put 100000 in <code>for</code> loop so it shows the pattern I noticed emerging. We have 1 million pixel to use, still random X and Y creates this pattern instead:
  <a href="https://i.stack.imgur.com/6ObjF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6ObjF.png" alt="enter image description here"></a></p>
  
  <p>So it is far from random. I know rand is not real random, that is why it isn't good for cryptography. But I find no information about how it works and what should I do to avoid patterns like this.</p>