using System; using System.Collections.Generic; using System.Linq; using System.Text; public static String RandomString(Int32 length) { Random randomGenerator; String returnValue; randomGenerator = new Random(); returnValue = new string(Enumerable.Range(0, length).Select(i => (char)(‘A’ + randomGenerator.Next(0, 25))).ToArray()); return returnValue; } What this does: Enumerable.Range basically says, “Give me a collection of numbers from the first parameter to the second”, or [...]
Tag Archives: Random
Random Enumeration Generator with Generics
public static I RandomEnumeration<I>() { I enumerationToCheck; Int32 indexToUse; String[] names; //Use activator to create an instance of the type I enumerationToCheck = System.Activator.CreateInstance<I>(); //Make sure the instance is an Enumeration //Unfortunately you can’t check that in the method //delcaring using “which”. if (enumerationToCheck as Enum == null) { throw new InvalidOperationException(); } //Get the [...]