title: Why does NumPy's random function seemingly display a pattern in its generated values?
body: <p>I was playing around with NumPy and Pillow and came across an interesting result that apparently showcases a pattern in NumPy <code>random.random()</code> results.</p>
  
  <p><a href="https://i.stack.imgur.com/zeJPU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/zeJPU.png" alt="Image One"></a> <a href="https://i.stack.imgur.com/1aZua.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1aZua.png" alt="Image Two"></a> <a href="https://i.stack.imgur.com/YOVsV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YOVsV.png" alt="Image Three"></a> <a href="https://i.stack.imgur.com/u18BH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/u18BH.png" alt="Image Four"></a></p>
  
  <p>Here a sample of the full code for generating and saving 100 of these images (with seed 0), the above are the first four images generated by this code.</p>
  
  <pre><code>import numpy as np
  from PIL import Image
  
  np.random.seed(0)
  img_arrays = np.random.random((100, 256, 256, 3)) * 255
  for i, img_array in enumerate(img_arrays):
      img = Image.fromarray(img_array, "RGB")
      img.save("{}.png".format(i))
  </code></pre>
  
  <p>The above are four different images created using <code>PIL.Image.fromarray()</code> on four different NumPy arrays created using <code>numpy.random.random((256, 256, 3)) * 255</code> to generate a 256 by 256 grid of RGB values in four different Python instances (the same thing also happens in the same instance).</p>
  
  <p>I noticed that this only happens (in my limited testing) when the width and height of the image is a power of two, I am not sure how to interpret that.</p>
  
  <p>Although it may be hard to see due to browser anti-aliasing (you can download the images and view them in image viewers with no anti-aliasing), there are clear purple-brown columns of pixels every 8th column starting from the 3rd column of every image. To make sure, I tested this on 100 different images and they all followed this pattern.</p>
  
  <p>What is going on here? I am guessing that patterns like this are the reason that people always say to use cryptographically secure random number generators when true randomness is required, but is there a concrete explanation behind why this is happening in particular?</p>