Skip to content

Repository files navigation

Exceptionless.RandomData

Build statusNuGet VersionDiscordDonate

A utility library for generating random data in .NET. Makes generating realistic test data a breeze. Targets net8.0 and net10.0.

Getting Started

This package can be installed via the NuGet package manager. If you need help, please contact us via in-app support or open an issue. We're always here to help if you have any questions!

dotnet add package Exceptionless.RandomData

Usage

All methods are on the static RandomData class in the Exceptionless namespace.

Numbers

usingExceptionless;intvalue=RandomData.GetInt(1,100);longbig=RandomData.GetLong(0,1_000_000);doubled=RandomData.GetDouble(0.0,1.0);decimalm=RandomData.GetDecimal(1,500);

Booleans

usingExceptionless;boolcoin=RandomData.GetBool();boollikely=RandomData.GetBool(chance:80);// 80% chance of true

Strings

usingExceptionless;stringrandom=RandomData.GetString(minLength:5,maxLength:20);stringalpha=RandomData.GetAlphaString(10,10);stringalphaNum=RandomData.GetAlphaNumericString(8,16);

Words, Sentences, and Paragraphs

usingExceptionless;stringword=RandomData.GetWord();stringtitle=RandomData.GetTitleWords(minWords:3,maxWords:6);stringsentence=RandomData.GetSentence(minWords:5,maxWords:15);stringtext=RandomData.GetParagraphs(count:2,minSentences:3,maxSentences:10);stringhtml=RandomData.GetParagraphs(count:2,html:true);

Dates and Times

usingExceptionless;DateTimedate=RandomData.GetDateTime();DateTimerecent=RandomData.GetDateTime(start:DateTime.UtcNow.AddDays(-30),end:DateTime.UtcNow);DateTimeOffsetdto=RandomData.GetDateTimeOffset();TimeSpanspan=RandomData.GetTimeSpan(min:TimeSpan.FromMinutes(1),max:TimeSpan.FromHours(2));

Enums

usingExceptionless;DayOfWeekday=RandomData.GetEnum<DayOfWeek>();

Network and Versioning

usingExceptionless;stringip=RandomData.GetIp4Address();// e.g. "192.168.4.12"stringcoord=RandomData.GetCoordinate();// e.g. "45.123,-90.456"stringversion=RandomData.GetVersion("1.0","5.0");

Pick Random from Collection

The Random<T>() extension method picks a random element from any IEnumerable<T>:

usingExceptionless;int[]numbers=[1,2,3,4,5];intpicked=numbers.Random();string[]names=["Alice","Bob","Charlie"];string?name=names.Random();

Thanks to all the people who have contributed

contributors

Releases

Sponsor this project

Packages

Used by

Contributors

Languages