Skip to content

Instantly share code, notes, and snippets.

@aruku7230
Last active September 4, 2023 07:45
Show Gist options
  • Save aruku7230/8f361008707b42bf83f1988010396dc4 to your computer and use it in GitHub Desktop.
Save aruku7230/8f361008707b42bf83f1988010396dc4 to your computer and use it in GitHub Desktop.
Create file filled with random characters

Get Random String

using System;
using System.Text;
					
public class Program
{
	public static void Main()
	{
		Console.WriteLine(GetRandomString(0));
		Console.WriteLine(GetRandomString(10));
		Console.WriteLine(GetRandomString(200));
	}
	
	private static string GetRandomString(int length)
	{
		var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		var rndGenerator = new Random();
		var result = new StringBuilder(length);
		for(int i = 0; i < length; i++)
		{
			result.Append(chars[rndGenerator.Next(chars.Length)]);
		}
		
		return result.ToString();
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment