Skip to content

Instantly share code, notes, and snippets.

@khalilovcmd
Last active September 22, 2022 10:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khalilovcmd/494988c43b6c205f9d76 to your computer and use it in GitHub Desktop.
Save khalilovcmd/494988c43b6c205f9d76 to your computer and use it in GitHub Desktop.
Generate a number of random ascii characters in C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Randomizer
{
public class Program
{
static void Main(string[] args)
{
int asciiCharacterStart = 65; // from which ascii character code the generation should start
int asciiCharacterEnd = 122; // to which ascii character code the generation should end
int characterCount = 10000; // count of characters to generate
Random random = new Random(DateTime.Now.Millisecond);
StringBuilder builder = new StringBuilder();
// iterate, get random int between 'asciiCharacterStart' and 'asciiCharacterEnd', then convert it to (char), append to StringBuilder
for (int i = 0; i < characterCount; i++)
builder.Append((char)(random.Next(asciiCharacterStart, asciiCharacterEnd + 1) % 255));
// voila!
String text = builder.ToString();
}
}
}
@tuncturel
Copy link

Lovely script mate! Borrowed it and played around with it a little bit to make some text glitcher.

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