Generate big amount of pseudorandom data predictably

Well, most people just go with badblocks...

Otherwise, just encrypt zeroes. Encryption does exactly what you want. Encrypted zeroes look like random data. Decrypting random data turns it back into zeroes. It's deterministic, reversible so as long as you know the key.

cryptsetup open --type plain --cipher aes-xts-plain64 /dev/yourdisk cryptodisk
shred -n 0 -z -v /dev/mapper/cryptodisk # overwrites everything
cmp /dev/zero /dev/mapper/cryptodisk    # byte-by-byte comparison

This should utilize full disk speed on a modern system with AES-NI.


Also kind of works for just piping (without backed by real storage)

truncate -s 1E exabyte_of_zero
losetup --find --show --read-only exabyte_of_zero
cryptsetup open --type plain --cipher aes-xts-plain64 --readonly /dev/loop4
cat /dev/mapper/loopcrypt | something_that_wanted_random_data

or if we're still writing to a disk and comparing

cat /dev/mapper/loopcrypt > /dev/sdx
# overwrites until no space left on device
cmp /dev/mapper/loopcrypt /dev/sdx
# compares until EOF on /dev/sdx OR loopcrypt and sdx differ byte X.

Unlike PRNG this can also be used to start comparing data somewhere in the middle of the file. With a traditional PRNG you have to re-generate it all over again to reach back to whatever position you were interested in. Of course, you could just make a random seed based on offset or something...

Tags:

Random