diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2021-04-01 22:36:59 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2021-04-01 22:36:59 +0200 |
| commit | 9e0fbac6d3cb4e11efdb33c339ccf0adbca0bc6c (patch) | |
| tree | 8fd1e8710abc3b17f0bc7f960c89931efd83c944 /src/IOL.Helpers/RandomStringGenerator.cs | |
| download | dotnet-helpers-9e0fbac6d3cb4e11efdb33c339ccf0adbca0bc6c.tar.xz dotnet-helpers-9e0fbac6d3cb4e11efdb33c339ccf0adbca0bc6c.zip | |
Initial commit
Diffstat (limited to 'src/IOL.Helpers/RandomStringGenerator.cs')
| -rw-r--r-- | src/IOL.Helpers/RandomStringGenerator.cs | 18 |
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 |
