Skip to content

Instantly share code, notes, and snippets.

@Edkorenkov
Last active August 11, 2022 09:02
Show Gist options
  • Save Edkorenkov/6de931b2105fe7ab3546a1f93622a6e9 to your computer and use it in GitHub Desktop.
Save Edkorenkov/6de931b2105fe7ab3546a1f93622a6e9 to your computer and use it in GitHub Desktop.
Random robot name generator in format of XX123 where XX : letters from A to Z
var name = Guid.NewGuid()
.ToString()
.Aggregate("", (acc, x) =>
{
return acc.Length switch
{
< 2 when char.IsLetter(x) => $"{acc}{x.ToString().ToUpper()}",
>= 2 and < 5 when char.IsDigit(x) => $"{acc}{x.ToString()}",
_ => acc
};
});
var name = Guid.NewGuid()
.ToString()
.Where(char.IsLetter)
.Take(2)
.Select(x => x.ToString())
.Concat(Enumerable.Range(0, 3).Select(_ => $"{RandomNumberGenerator.GetInt32(0, 9)}"))
.Aggregate("", (z, x) => $"{z}{x}")
.ToUpper();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment