Random file generator (again!)

I really need a random file generator that creates really random, non-compressible files .

I ended up with this delphi code. It works, but it hurts sloooow

var Buf : Integer; TheFile : TFileStream; begin TheFile := TFileStream.Create(FileName, fmCreate OR fmOpenReadWrite); with TheFile do begin for i := 0 to FileSize do // Iterate begin Buf := Random(999999) * i; WriteBuffer(Buf, SizeOf(Buf)); end; // for end; // with end, 

My question is: is there a quick random file generator that I can use? Both Delphi codes and / or command line tools are acceptable if:

  • I can run it on Windows without manual intervention (I need it for my tests, no intervention is allowed)
  • quickly
  • Generated files are not compressible (i.e., compression of the generated file does not require space saving)

EDIT . For those who are interested, I applied the advice I gave and made this function , it is fast enough and 7zip makes it difficult to compress the generated data.

+6
source share
2 answers

Use a 4096-byte page size or multiple page size buffers. Recording one whole at a time will be slow.

+9
source

You can use my generate_random_file.py script (Python 3), which I used to generate test data in my project.

  • It works on both Linux and Windows.
  • This is very fast because it uses os.urandom() to generate random data in 256 KiB chunks instead of generating and writing each byte separately.
+1
source

Source: https://habr.com/ru/post/913569/


All Articles