Skip to content
James Craig edited this page Mar 23, 2015 · 1 revision

The library has a number of random generator extensions to add to the built in functions in the System.Random class. The first of these is the generic Next function:

var Result=new System.Random().Next<byte>(1,29); //Returns a byte value between 1 and 29.

This can take, more or less, any basic primitive type and generate a random value. Min and max values can be specified but if they're missing then it just takes the Min/Max for the value type. It also contains a number of string generators. The default is a simple Lorem Ipsum generator:

var Result=new System.Random().Next<string>();

This one just generates a random Lorem Ipsum paragraph. The more interesting function though is NextClass:

var Result=new System.Random().NextClass<MyClass>();

This generates a class, filling in the various properties that are using the appropriate attributes:

public class RandomTestClass
{
    [IntGenerator]
    public int A { get; set; }

    [LoremIpsumGenerator]
    public string B { get; set; }

    [FloatGenerator]
    public float C { get; set; }

    [IntGenerator(1, 100)]
    public int D { get; set; }
}

There are even generators to help with generating names (male, female, portions of a name like last name, suffix, etc), companies, addresses, cities, domain names, email addresses, phone numbers, states, zip codes, etc. You can even create your own generator attribute and the system will pick them up when generating the class. The class that you would need to inherit from is GeneratorAttributeBase found in the Utilities.Random.BaseClasses namespace.

Clone this wiki locally