diff --git a/Mk0.Tools.Randomization.sln b/Mk0.Tools.Randomization.sln new file mode 100644 index 0000000..5da94a1 --- /dev/null +++ b/Mk0.Tools.Randomization.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.438 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mk0.Tools.Randomization", "Mk0.Tools.Randomization\Mk0.Tools.Randomization.csproj", "{B5391664-66E2-4C4E-BCDA-089B446B9034}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B5391664-66E2-4C4E-BCDA-089B446B9034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5391664-66E2-4C4E-BCDA-089B446B9034}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5391664-66E2-4C4E-BCDA-089B446B9034}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5391664-66E2-4C4E-BCDA-089B446B9034}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {39C91CEC-87C1-438E-BD56-D381D86CFCA9} + EndGlobalSection +EndGlobal diff --git a/Mk0.Tools.Randomization/Mk0.Tools.Randomization.csproj b/Mk0.Tools.Randomization/Mk0.Tools.Randomization.csproj new file mode 100644 index 0000000..6fbe5fc --- /dev/null +++ b/Mk0.Tools.Randomization/Mk0.Tools.Randomization.csproj @@ -0,0 +1,43 @@ + + + + + Debug + AnyCPU + {B5391664-66E2-4C4E-BCDA-089B446B9034} + Library + Properties + Mk0.Tools.Randomization + Mk0.Tools.Randomization + v4.6.1 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + \ No newline at end of file diff --git a/Mk0.Tools.Randomization/Properties/AssemblyInfo.cs b/Mk0.Tools.Randomization/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aa135a7 --- /dev/null +++ b/Mk0.Tools.Randomization/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Mk0.Tools.Randomization")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Mk0.Tools.Randomization")] +[assembly: AssemblyCopyright("Copyright © 2019 mk0.at")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("b5391664-66e2-4c4e-bcda-089b446b9034")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Mk0.Tools.Randomization/Randomize.cs b/Mk0.Tools.Randomization/Randomize.cs new file mode 100644 index 0000000..a680c53 --- /dev/null +++ b/Mk0.Tools.Randomization/Randomize.cs @@ -0,0 +1,83 @@ +using System; +using System.Text; + +namespace Mk0.Tools.Randomization +{ + public class Randomize + { + /// + /// Generiert einen zufälligen String aus Zahlen und Buchstaben mit optionalem Endzeichen + /// + /// + /// + /// Zufallsstring + public static string NumbersAndDigits(int length, string beginnzeichen = "", string endzeichen = "") + { + string ret = string.Empty; + StringBuilder SB = new StringBuilder(); + string Content = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw"; + Random rnd = new Random(); + if (beginnzeichen != "") + { + SB.Append(beginnzeichen); + } + for (int i = 0; i < length; i++) + SB.Append(Content[rnd.Next(Content.Length)]); + if (endzeichen != "") + { + SB.Append(endzeichen); + } + return SB.ToString(); + } + + /// + /// Generiert einen zufälligen String Buchstaben mit optionalem Endzeichen + /// + /// + /// + /// Zufallsstring + public static string Digits(int length, string beginnzeichen = "", string endzeichen = "") + { + string ret = string.Empty; + StringBuilder SB = new StringBuilder(); + string Content = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw"; + Random rnd = new Random(); + if (beginnzeichen != "") + { + SB.Append(beginnzeichen); + } + for (int i = 0; i < length; i++) + SB.Append(Content[rnd.Next(Content.Length)]); + if (endzeichen != "") + { + SB.Append(endzeichen); + } + return SB.ToString(); + } + + /// + /// Generiert einen zufälligen String aus Zahlen mit optionalem Endzeichen + /// + /// + /// + /// Zufallsstring + public static string Numbers(int length, string beginnzeichen = "", string endzeichen = "") + { + string ret = string.Empty; + StringBuilder SB = new StringBuilder(); + string Content = "1234567890"; + Random rnd = new Random(); + if (beginnzeichen != "") + { + SB.Append(beginnzeichen); + } + for (int i = 0; i < length; i++) + SB.Append(Content[rnd.Next(Content.Length)]); + if (endzeichen != "") + { + SB.Append(endzeichen); + } + return SB.ToString(); + } + } +} diff --git a/README.md b/README.md index 796ec2b..b368c45 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# Mk0.Tools.Randomization \ No newline at end of file +# Mk0.Tools.Randomization +(C) 2019 mk0.at + +Allows you to generate a random string with a length of your choice. +You can add an optional prefix and an optional appendix to the random string. + +You can use the following methods: + ++ NumbersAndDigits (1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw) ++ Digits (ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw) ++ Numbers (1234567890) + +Example usage: + +Randomize.NumbersAndDigits(5, "_") +will return f.e. "_j7Ga9" + +Randomize.Numbers(2, "*", "#") +will return f.w. "*59#" + +Randomize.Digits(3) +will return f.w. "fOu" \ No newline at end of file