Skip to content

Instantly share code, notes, and snippets.

@kmark
Created January 6, 2022 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmark/785ac53e488e54f319811627636f33f6 to your computer and use it in GitHub Desktop.
Save kmark/785ac53e488e54f319811627636f33f6 to your computer and use it in GitHub Desktop.
<?php
// Quick script to get some not-cryptographically-secure random data
// to stdout in a portable way. Useful for generating uncompressable
// test files
define("INTS_PER_LOOP", 4096);
$f = str_repeat("l", INTS_PER_LOOP);
$r = []; // Using SplFixedArray is actually slower
mt_srand(random_int(PHP_INT_MIN, PHP_INT_MAX));
while (true) {
for ($i = 0; $i < INTS_PER_LOOP; $i++) {
$r[$i] = mt_rand();
}
echo pack($f, ...$r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment