A utility library for generating random data in .NET. Makes generating realistic test data a breeze. Targets net8.0 and net10.0.
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
All methods are on the static RandomData class in the Exceptionless namespace.
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);usingExceptionless;boolcoin=RandomData.GetBool();boollikely=RandomData.GetBool(chance:80);// 80% chance of trueusingExceptionless;stringrandom=RandomData.GetString(minLength:5,maxLength:20);stringalpha=RandomData.GetAlphaString(10,10);stringalphaNum=RandomData.GetAlphaNumericString(8,16);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);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));usingExceptionless;DayOfWeekday=RandomData.GetEnum<DayOfWeek>();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");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();