Class RandomExtensions
  
  Extensions to System.Random in order to randomly generate
types and specially formatted strings that assist with testing
custom extensions to Lucene.Net.
 
  
  
    Inheritance
    System.Object
    RandomExtensions
   
  
    Inherited Members
    
      System.Object.Equals(System.Object)
    
    
      System.Object.Equals(System.Object, System.Object)
    
    
      System.Object.GetHashCode()
    
    
      System.Object.GetType()
    
    
      System.Object.MemberwiseClone()
    
    
      System.Object.ReferenceEquals(System.Object, System.Object)
    
    
      System.Object.ToString()
    
   
  
  Assembly: Lucene.Net.TestFramework.dll
  Syntax
  
    public static class RandomExtensions
   
  Methods
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextAnalysisString(Random, Int32, Boolean)
  
  
  Declaration
  
    public static string NextAnalysisString(this Random random, int maxLength, bool simple)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
      
        | System.Boolean | 
        simple | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextBoolean(Random)
  Generates a random System.Boolean, with a random distribution of
approximately 50/50.
 
  
  Declaration
  
    public static bool NextBoolean(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
        This System.Random. 
 | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Boolean | 
        A random System.Boolean. 
 | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextFilterStrategy(Random)
  
  
  Declaration
  
    public static FilteredQuery.FilterStrategy NextFilterStrategy(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
    
  
  Returns
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextFixedByteLengthUnicodeString(Random, Int32)
  Returns random string, with a given UTF-8 byte length. 
 
  
  Declaration
  
    public static string NextFixedByteLengthUnicodeString(this Random random, int length)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        length | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextFixedLengthUnicodeString(Random, Char[], Int32, Int32)
  Fills provided char[] with valid random unicode code
unit sequence.
 
  
  Declaration
  
    public static void NextFixedLengthUnicodeString(this Random random, char[] chars, int offset, int length)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Char[] | 
        chars | 
         | 
      
      
        | System.Int32 | 
        offset | 
         | 
      
      
        | System.Int32 | 
        length | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextFrom<T>(Random, ICollection<T>)
  Pick a random object from the collection.
 
  
  Declaration
  
    public static T NextFrom<T>(this Random random, ICollection<T> collection)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Collections.Generic.ICollection<T> | 
        collection | 
         | 
      
    
  
  Returns
  
  Type Parameters
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextHtmlishString(Random, Int32)
  Returns a random HTML-like string.
 
  
  Declaration
  
    public static string NextHtmlishString(this Random random, int numElements)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        numElements | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextInt64(Random)
  Generates a random System.Int64.
 
  
  Declaration
  
    public static long NextInt64(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
        This System.Random. 
 | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int64 | 
        A random System.Int64. 
 | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextInt64(Random, Int64, Int64)
  Generates a random System.Int64. start and end are BOTH inclusive.
 
  
  Declaration
  
    public static long NextInt64(this Random random, long start, long end)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
        This System.Random. 
 | 
      
      
        | System.Int64 | 
        start | 
        The inclusive start. 
 | 
      
      
        | System.Int64 | 
        end | 
        The inclusive end. 
 | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Int64 | 
        A random System.Int64. 
 | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextRealisticUnicodeString(Random)
  Returns random string of length between 0-20 codepoints, all codepoints within the same unicode block. 
 
  
  Declaration
  
    public static string NextRealisticUnicodeString(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextRealisticUnicodeString(Random, Int32)
  Returns random string of length up to maxLength codepoints, all codepoints within the same unicode block. 
 
  
  Declaration
  
    public static string NextRealisticUnicodeString(this Random random, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextRealisticUnicodeString(Random, Int32, Int32)
  Returns random string of length between min and max codepoints, all codepoints within the same unicode block. 
 
  
  Declaration
  
    public static string NextRealisticUnicodeString(this Random random, int minLength, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        minLength | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextRecasedString(Random, String)
  Randomly upcases, downcases, or leaves intact each code point in the given string.
 
  
  Declaration
  
    public static string NextRecasedString(this Random random, string str)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.String | 
        str | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextRegex(Random)
  Returns a valid (compiling) System.Text.RegularExpressions.Regex instance with random stuff inside. Be careful
when applying random patterns to longer strings as certain types of patterns
may explode into exponential times in backtracking implementations (such as Java's).
 
  
  Declaration
  
    public static Regex NextRegex(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Text.RegularExpressions.Regex | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextRegexishString(Random)
  Returns a System.String thats "regexish" (contains lots of operators typically found in regular expressions)
If you call this enough times, you might get a valid regex!
 
  
  Declaration
  
    public static string NextRegexishString(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextRegexishString(Random, Int32)
  Returns a System.String thats "regexish" (contains lots of operators typically found in regular expressions)
If you call this enough times, you might get a valid regex!
Note: to avoid practically endless backtracking patterns we replace asterisk and plus
operators with bounded repetitions. See LUCENE-4111 for more info.
 
  
  Declaration
  
    public static string NextRegexishString(this Random random, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
        A hint about maximum length of the regexpish string. It may be exceeded by a few characters.  
 | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextSimpleString(Random)
  Returns a random string consisting only of lowercase characters 'a' through 'z',
between 0 and 20 characters in length.
 
  
  Declaration
  
    public static string NextSimpleString(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextSimpleString(Random, Int32)
  Returns a random string consisting only of lowercase characters 'a' through 'z'.
 
  
  Declaration
  
    public static string NextSimpleString(this Random random, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextSimpleString(Random, Int32, Int32)
  Returns a random string consisting only of lowercase characters 'a' through 'z'.
 
  
  Declaration
  
    public static string NextSimpleString(this Random random, int minLength, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        minLength | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextSimpleStringRange(Random, Char, Char, Int32)
  Returns a random string consisting only of characters between minChar and maxChar.
 
  
  Declaration
  
    public static string NextSimpleStringRange(this Random random, char minChar, char maxChar, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Char | 
        minChar | 
         | 
      
      
        | System.Char | 
        maxChar | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextSingle(Random)
  Generates a random System.Single.
 
  
  Declaration
  
    public static float NextSingle(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
        This System.Random. 
 | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.Single | 
        A random System.Single. 
 | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextSubString(Random, Int32, Boolean)
  
  
  Declaration
  
    public static string NextSubString(this Random random, int wordLength, bool simple)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        wordLength | 
         | 
      
      
        | System.Boolean | 
        simple | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextUnicodeString(Random)
  Returns random string, including full unicode range. 
 
  
  Declaration
  
    public static string NextUnicodeString(this Random random)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextUnicodeString(Random, Int32)
  Returns a random string up to a certain length.
 
  
  Declaration
  
    public static string NextUnicodeString(this Random random, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  
    |
    Improve this Doc
  
  
    View Source
  
  
  NextWhitespace(Random, Int32, Int32)
  Returns a random string in the specified length range consisting
entirely of whitespace characters.
 
  
  Declaration
  
    public static string NextWhitespace(this Random random, int minLength, int maxLength)
   
  Parameters
  
    
      
        | Type | 
        Name | 
        Description | 
      
    
    
      
        | System.Random | 
        random | 
         | 
      
      
        | System.Int32 | 
        minLength | 
         | 
      
      
        | System.Int32 | 
        maxLength | 
         | 
      
    
  
  Returns
  
    
      
        | Type | 
        Description | 
      
    
    
      
        | System.String | 
         | 
      
    
  
  See Also