![]() |
VOOZH | about |
dotnet add package RandomizedTesting.Generators --version 2.7.8
NuGet\Install-Package RandomizedTesting.Generators -Version 2.7.8
<PackageReference Include="RandomizedTesting.Generators" Version="2.7.8" />
<PackageVersion Include="RandomizedTesting.Generators" Version="2.7.8" />Directory.Packages.props
<PackageReference Include="RandomizedTesting.Generators" />Project file
paket add RandomizedTesting.Generators --version 2.7.8
#r "nuget: RandomizedTesting.Generators, 2.7.8"
#:package RandomizedTesting.Generators@2.7.8
#addin nuget:?package=RandomizedTesting.Generators&version=2.7.8Install as a Cake Addin
#tool nuget:?package=RandomizedTesting.Generators&version=2.7.8Install as a Cake Tool
👁 Nuget
👁 Azure DevOps builds (branch)
👁 GitHub
👁 GitHub Sponsors
This is a C# port of the only the generators from the Java randomizedtesting library.
In addition to the random generators, the RandomExtensions class contains several useful low-level extension methods for generating numbers, text (html-like, regex-like, unicode, realistic unicode, plain ASCII), random picks from collections, or random regular expression instances.
Why would you want tests to have random data? This is to fill situations where it is not practical to test the entire range of values in a single test run, for example, with applications that analyze text. Tests can instead be designed to provide different input every time they run to catch edge cases that are difficult to test for. Generating random data also has many other purposes, such as quickly generating a set of text files to benchmark with without having to store several hundred MB worth of files (since the same random seed will always generate the same data).
// Create a System.Random instance
Random random = new Random();
// Create a random bool
bool boolValue = random.NextBoolean();
// Create a random long
long longValue = random.NextInt64();
// Create a random long between 10 (inclusive) and 100 (inclusive)
long longRangeValue = random.NextInt64(minValue: 10, maxValue: 100);
// Create a random float
float floatValue = random.NextSingle();
// Create a random BigInteger (from System.Numerics)
BigInteger bigIntValue = random.NextBigInteger();
// Pick a random KeyValuePair from a generic dictionary
var dictionary = new Dictionary<string, string>
{
["one"] = "oneValue",
["two"] = "twoValue",
["three"] = "threeValue",
["four"] = "fourValue",
["five"] = "fiveValue",
};
KeyValuePair<string, string> kvp = random.NextFrom(dictionary);
// Pick a random element from an array
var array = new int[] { 1, 4, 7, 10, 14, 74, 136 };
var arrayElement = random.RandomFrom(array);
// Create a random string (plain ASCII)
string asciiValue = random.NextSimpleString(maxLength: 15);
// Create a random string with specific chars
string specValue = random.NextSimpleStringRange(minChar: 'A', maxChar: 'F', maxLength: 10);
// Create a random Unicode string (may contain surrogate pairs)
string unicodeValue = random.NextUnicodeString(maxLength: 20);
// Create a random realistic Unicode string (random characters picked from the same Unicode block)
string realUnicodeValue = random.NextRealisticUnicodeString(maxLength: 30);
// Fill part of a char[] with random Unicode characters
char[] chars = "The quick brown fox jumped over the lazy dog.".ToCharArray();
random.NextFixedLengthUnicodeString(chars, startIndex: 8, length: 20);
// Generate a random regex-like string
string regexLike = random.NextRegexishString(maxLength: 20);
// Generate a random HTML-like string
string htmlLike = random.NextHtmlishString(numElements: 144);
// Randomly recase a string
string toRecase = "This Is A Pascal Cased String";
string recased = random.NextStringRecasing(toRecase);
// Generate a random Regex that compiles
Regex pattern = random.NextRegex();
To build the project from source, see the Building and Testing documentation.
If you find this library to be useful, please star us on GitHub and consider a financial sponsorship so we can continue bringing you great free tools like this one.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net45 net45 is compatible. net451 net451 was computed. net452 net452 was computed. net46 net46 was computed. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on RandomizedTesting.Generators:
| Package | Downloads |
|---|---|
|
Lucene.Net.TestFramework
Framework for testing Lucene.NET-based applications using NUnit. Documentation: https://lucenenet.apache.org/docs/4.8.0-beta00018/api/test-framework/overview.html This package is part of the Lucene.NET project: https://www.nuget.org/packages/Lucene.Net/4.8.0-beta00018 |
|
|
RandomizedTesting
This is a package dependency that is not meant to be referenced directly. Please use https://www.nuget.org/packages/RandomizedTesting.Generators instead. |
Showing the top 1 popular GitHub repositories that depend on RandomizedTesting.Generators:
| Repository | Stars |
|---|---|
|
apache/lucenenet
Apache Lucene.NET is an open-source full-text search library written in C#, ported from the Apache Lucene project.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.7.8 | 216,964 | 1/15/2022 |
| 2.7.8-beta-0002 | 13,280 | 10/24/2021 |
| 2.7.8-beta-0001 | 10,863 | 4/20/2021 |