public IDGenerator(String key, IRangeGenerator <T> rangeGenerator) { this.key = key.ToUpperInvariant(); this.rangeGenerator = rangeGenerator; this.startRange = default(T); this.endRange = default(T); }
public static IIDGenerator <T> Create(string key, IRangeGenerator <T> rg) { IIDGenerator <T> idGen = null; if (false == idGenerators.TryGetValue(key, out idGen)) { switch (typeof(T).FullName) { case "System.Int64": { idGen = (IIDGenerator <T>) new Int64IDGenertor(key, (IRangeGenerator <Int64>)rg); break; } case "System.Int32": { idGen = (IIDGenerator <T>) new Int32IDGenertor(key, (IRangeGenerator <Int32>)rg); break; } case "System.Int16": { idGen = (IIDGenerator <T>) new Int16IDGenertor(key, (IRangeGenerator <Int16>)rg); break; } } if (!idGenerators.TryAdd(key, idGen)) { throw new Exception("Cannot create ID Generator."); } } return(idGen); }
/// <summary> /// Fills a portion of a provided character buffer with random characters using the provided character set. /// </summary> /// <param name="random">The pseudo-random engine that will be used to generate bits from which the return value is derived.</param> /// <param name="buffer">The character buffer to which random charactors will be written.</param> /// <param name="start">The start index of the character buffer where random character generation will begin. Must be less than or equal to <paramref name="buffer"/>.Length - <paramref name="length"/>.</param> /// <param name="length">The number of random characters to be generated. Must be less than or equal to <c><paramref name="buffer"/>.Length - <paramref name="start"/></c>.</param> /// <param name="characters">The allowable characters to select from when generating the string.</param> /// <seealso cref="Characters(IRandom, char[], int, int, char[], char, float, bool, bool, bool)"/> /// <seealso cref="String(IRandom, int, char[])"/> public static void Characters(this IRandom random, char[] buffer, int start, int length, char[] characters) { if (length <= 0) { return; } int end = start + length; IRangeGenerator <int> generator = random.MakeRangeCOGenerator(characters.Length); for (int i = start; i < end; ++i) { buffer[i] = characters[generator.Next()]; } }
private static string Base64String(this IRandom random, int length, char[] characters) { if (length <= 0) { return(""); } char[] buffer = new char[length]; IRangeGenerator <int> generator = random.MakeRangeCOGenerator(64); for (int i = 0; i < length; ++i) { buffer[i] = characters[generator.Next()]; } return(new string(buffer)); }
/// <summary> /// Generates a random string representing a sequence of decimal digits. /// </summary> /// <param name="random">The pseudo-random engine that will be used to generate bits from which the return value is derived.</param> /// <param name="length">The length of the string to be generated.</param> /// <returns>A random string, with each character being a uniformly random selection decimal digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }.</returns> public static string DecimalString(this IRandom random, int length) { if (length <= 0) { return(""); } char[] buffer = new char[length]; IRangeGenerator <int> generator = random.MakeRangeCOGenerator(10); for (int i = 0; i < length; ++i) { buffer[i] = (char)('0' + generator.Next()); } return(new string(buffer)); }
/// <summary> /// Generates a random string representing a sequence of decimal digits. /// </summary> /// <param name="random">The pseudo-random engine that will be used to generate bits from which the return value is derived.</param> /// <param name="length">The length of the string to be generated.</param> /// <returns>A random string, with each character being a uniformly random selection decimal digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }.</returns> /// <remarks>Upper case letters are used for the digits A through F. If you want to control /// the letter casing used, see <see cref="HexadecimalString(IRandom, int, Casing)"/>.</remarks> /// <seealso cref="Casing"/> /// <seealso cref="HexadecimalString(IRandom, int, Casing)"/> public static string HexadecimalString(this IRandom random, int length) { if (length <= 0) { return(""); } char[] buffer = new char[length]; IRangeGenerator <int> generator = random.MakeRangeCOGenerator(16); for (int i = 0; i < length; ++i) { buffer[i] = _upperHexadecimalCharacters[generator.Next()]; } return(new string(buffer)); }
/// <summary> /// Fills a portion of a provided character buffer with random characters using the provided character set. /// </summary> /// <param name="random">The pseudo-random engine that will be used to generate bits from which the return value is derived.</param> /// <param name="buffer">The character buffer to which random charactors will be written.</param> /// <param name="start">The start index of the character buffer where random character generation will begin. Must be less than or equal to <paramref name="buffer"/>.Length - <paramref name="length"/>.</param> /// <param name="length">The number of random characters to be generated. Must be less than or equal to <c><paramref name="buffer"/>.Length - <paramref name="start"/></c>.</param> /// <param name="characters">The allowable characters to select from when generating the string.</param> /// <param name="separator">The separator character to be randomly inserted into the string according to the probability specified.</param> /// <param name="separatorProbability">The probability of any specific index in the string being a separator character. Must be in the range [0, 1].</param> /// <param name="allowSeparatorAtEnd">Whether or not the last character to be generated is allowed to be a separator character.</param> /// <param name="allowSeparatorAtBegin">Whether or not the first character to be generated is allowed to be a separator character.</param> /// <param name="forceSeparatorAtBegin">Whether or not the first character to be generated must be a separator character. Ignored if <paramref name="allowSeparatorAtBegin"/> is false.</param> /// <remarks><para>It is guaranteed that two separator characters will never be generated one immediately after the other within the /// character sequence, regardless of the separator probability.</para> /// <para>A separator probability of 0 will guarantee that there are no separators at all, while a probability of 1 will guarantee /// that every second character is a separtor character. Probabilities less than 1 but greater that 0.5 will be biased toward the /// same every-other character outcome, but will have a chance of generating longer sequences of non-separator characters, rather than /// being strictly limited to one non-separator character at a time.</para></remarks> /// <seealso cref="Characters(IRandom, char[], int, int, char[])"/> /// <seealso cref="String(IRandom, int, char[], char, float, bool, bool, bool)"/> public static void Characters(this IRandom random, char[] buffer, int start, int length, char[] characters, char separator, float separatorProbability, bool allowSeparatorAtEnd = false, bool allowSeparatorAtBegin = false, bool forceSeparatorAtBegin = false) { if (length <= 0) { return; } bool allowSeparatorState = allowSeparatorAtBegin; bool forceSeparatorState = forceSeparatorAtBegin; int end = start + length; IRangeGenerator <int> generator = random.MakeRangeCOGenerator(characters.Length); for (int i = start; i < end; ++i) { if (allowSeparatorState && (allowSeparatorAtEnd || i + 1 < end)) { if (forceSeparatorState || random.Probability(separatorProbability)) { buffer[i] = separator; allowSeparatorState = false; forceSeparatorState = false; } else { buffer[i] = characters[generator.Next()]; } } else { buffer[i] = characters[generator.Next()]; allowSeparatorState = true; forceSeparatorState = random.Probability(separatorProbability); } } }
public UIntWeightedProbabilityGenerator(IRandom random, uint numerator, uint denominator) { _rangeGenerator = random.MakeRangeCOGenerator(denominator); _numerator = numerator; }
public Int32IDGenertor(String key, IRangeGenerator <Int32> rangeGenerator) : base(key, rangeGenerator) { this.SetRange(); }
public ULongWeightedProbabilityGenerator(IRandom random, ulong numerator) { _rangeGenerator = random.MakeULongGenerator(); _numerator = numerator; }
public ULongWeightedProbabilityGenerator(IRandom random, ulong numerator, ulong denominator) { _rangeGenerator = random.MakeRangeCOGenerator(denominator); _numerator = numerator; }
public UIntWeightedProbabilityGenerator(IRandom random, uint numerator) { _rangeGenerator = random.MakeUIntGenerator(); _numerator = numerator; }
public Int64IDGenertor(String key, IRangeGenerator <Int64> rangeGenerator) : base(key, rangeGenerator) { }
public IntWeightedProbabilityGenerator(IRandom random, int numerator) { _rangeGenerator = random.MakeIntGenerator(true); _numerator = numerator; }
public DoubleWeightedProbabilityGenerator(IRandom random, double numerator, double denominator) { _rangeGenerator = random.MakeRangeCOGenerator(denominator); _numerator = numerator; }
public DoubleWeightedProbabilityGenerator(IRandom random, double numerator) { _rangeGenerator = random.MakeDoubleCOGenerator(); _numerator = numerator; }
public FloatWeightedProbabilityGenerator(IRandom random, float numerator, float denominator) { _rangeGenerator = random.MakeRangeCOGenerator(denominator); _numerator = numerator; }
public FloatWeightedProbabilityGenerator(IRandom random, float numerator) { _rangeGenerator = random.MakeFloatCOGenerator(); _numerator = numerator; }
private AngleGenerator(IRangeGenerator <float> rangeGenerator, float scale) { _rangeGenerator = rangeGenerator; _scale = scale; }
public LongWeightedProbabilityGenerator(IRandom random, long numerator) { _rangeGenerator = random.MakeLongGenerator(true); _numerator = numerator; }