Skip to content

Instantly share code, notes, and snippets.

@MiffOttah
Created November 8, 2021 22:28
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 MiffOttah/487352ad3ada6bbbe1b7974e6389e34c to your computer and use it in GitHub Desktop.
Save MiffOttah/487352ad3ada6bbbe1b7974e6389e34c to your computer and use it in GitHub Desktop.
using System;
using System.IO;
static class RngLs
{
static void Main()
{
const string PREFIXES = " kmgtpezy"; // karl marx gave the proletariat eleven zeppelins, yo
var files = new DirectoryInfo(Environment.CurrentDirectory).GetFiles();
var rng = new Random();
foreach (var file in files)
{
double size = file.Length;
if (rng.NextBool()) size *= 8; // bits or bytes? who knows!
// randomly select binary or decimal scaling
// not featured: kelly-bootle units, drivermaker's kilobytes, baker's kilobytes, or 1.44 mb floppy disks
double scaleFactor = rng.NextBool() ? 1000 : 1024;
int prefix = 0;
while (size >= scaleFactor * 1.5)
{
size /= scaleFactor;
prefix++;
}
// we'll just naievely assume that a file will never be 1.5 yb in size
// so this code probably won't work in a couple decades once moore's law makes average storage space
// so obscenely big that current SI cannot adequately describe it and wirth's law makes the average
// 20 second video about 3 yb big.
// what does "yb" mean here? who cares!
Console.Out.WriteLine($"{size,6:###0.0} {PREFIXES[prefix]}b - {file.Name}");
}
}
static bool NextBool(this Random rng) => rng.NextDouble() >= 0.5;
}
@WriterArtistCoder
Copy link

yo xkcd shoutout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment