Skip to content

Instantly share code, notes, and snippets.

@dhcgn
Last active August 1, 2016 14:50
Show Gist options
  • Save dhcgn/90071e2eb31863ff26a50d11e4252981 to your computer and use it in GitHub Desktop.
Save dhcgn/90071e2eb31863ff26a50d11e4252981 to your computer and use it in GitHub Desktop.
Create Random Data with c#
using System;
using System.IO;
using System.Linq;
namespace CreateRandomData
{
class Program
{
static void Main(string[] args)
{
var mb = 1;
if (args != null && args.Any())
{
int mbInput;
if (int.TryParse(args[0], out mbInput))
mb = mbInput;
}
if (mb == 0) return;
using (var stream = File.Create($"{Guid.NewGuid()}.bin"))
{
var rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);
var data = new byte[1024];
for (var i = 0; i <= 1024 * mb; i++)
{
if (i % mb == 0)
Console.Out.Write(".");
rnd.NextBytes(data);
stream.Write(data, 0, 1024);
}
}
Console.Out.WriteLine();
Console.Out.WriteLine("Done! Press any key.");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment