Generating random HTML color grid
An implementation that uses the random module has the benefit of being platform independent. This code isn't going to run so well if you try it on Windows.

There is also another alternative. os.urandom() will use the underlying os to provide the random values.


  On a UNIX-like system this will query /dev/urandom, and on Windows it
  will use CryptGenRandom().


You can also use random.SystemRandom() if you still want the OS source, but want to use the interface provided by random.



This answer provides an implementation of chunks() that iterates instead of constructing a list of all the chunks.



I would also lean towards an implementation that opens the output file first, then writes to it as it iterates over the chunks. This way, you won't need to build a huge string in memory before writing it to disk. Similarly, I would generate the random values as needed.