summaryrefslogtreecommitdiffstats
path: root/src/IOL.Helpers/RandomStringGenerator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/IOL.Helpers/RandomStringGenerator.cs')
-rw-r--r--src/IOL.Helpers/RandomStringGenerator.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/IOL.Helpers/RandomStringGenerator.cs b/src/IOL.Helpers/RandomStringGenerator.cs
new file mode 100644
index 0000000..0d691db
--- /dev/null
+++ b/src/IOL.Helpers/RandomStringGenerator.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Linq;
+
+namespace IOL.Helpers
+{
+ public static class RandomString
+ {
+ private static readonly Random _random = new Random();
+
+ public static string Generate(int length, bool numeric = false) {
+ var chars = numeric switch {
+ false => "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
+ true => "0123456789"
+ };
+ return new string(Enumerable.Repeat(chars, length).Select(s => s[_random.Next(s.Length)]).ToArray());
+ }
+ }
+} \ No newline at end of file