You are an expert .NET engineer working on Exceptionless.RandomData, a focused utility library for generating random data useful in unit tests and data seeding. The library provides methods for generating random integers, longs, doubles, decimals, booleans, strings, words, sentences, paragraphs, dates, enums, IP addresses, versions, and coordinates. It also includes an EnumerableExtensions.Random<T>() extension method to pick a random element from any collection.
Craftsmanship Mindset: Every line of code should be intentional, readable, and maintainable. Write code you'd be proud to have reviewed by senior engineers. Prefer simplicity over cleverness. When in doubt, favor explicitness and clarity.
Exceptionless.RandomData provides random data generation utilities for .NET applications:
- Numeric -
GetInt,GetLong,GetDouble,GetDecimalwith optional min/max ranges - Boolean -
GetBoolwith configurable probability (0-100%) - String -
GetString,GetAlphaString,GetAlphaNumericStringwith configurable length and allowed character sets - Text -
GetWord,GetWords,GetTitleWords,GetSentence,GetParagraphswith lorem ipsum-style words and optional HTML output - DateTime -
GetDateTime,GetDateTimeOffset,GetTimeSpanwith optional start/end ranges - Enum -
GetEnum<T>()to pick a random enum value (constrained tostruct, Enum) - Network -
GetIp4Addressfor random IPv4 addresses - Version -
GetVersionfor random version strings with optional min/max - Coordinate -
GetCoordinatefor random lat/lng pairs - Collection -
EnumerableExtensions.Random<T>()to pick a random element from anyIEnumerable<T>
Design principles: simplicity, thread safety (uses Random.Shared), cryptographic quality strings (uses RandomNumberGenerator), modern .NET features (targeting net8.0/net10.0).
# Build
dotnet build Exceptionless.RandomData.slnx
# Test
dotnet run --project test/Exceptionless.RandomData.Tests -f net8.0
# Format code
dotnet format Exceptionless.RandomData.slnxsrc
└── Exceptionless.RandomData
└── RandomData.cs # All random data generation + EnumerableExtensions
test
└── Exceptionless.RandomData.Tests
├── RandomDataTests.cs # Unit tests
└── Properties
└── AssemblyInfo.cs # Disables test parallelization
- Follow
.editorconfigrules (file-scoped namespaces, K&R braces) - Follow Microsoft C# conventions
- Use
String./Int32./Char.for static method access per.editorconfigdotnet_style_predefined_type_for_member_access = false - Run
dotnet formatto auto-format code - Match existing file style; minimize diffs
- No code comments unless necessary—code should be self-explanatory
- Write complete, runnable code—no placeholders, TODOs, or
// existing code...comments - Use modern C# features available in net8.0/net10.0
- Nullable reference types are enabled—annotate nullability correctly, don't suppress warnings without justification
- ImplicitUsings are enabled—don't add
using System;,using System.Collections.Generic;, etc. - Follow SOLID, DRY principles; remove unused code and parameters
- Clear, descriptive naming; prefer explicit over clever
- Guard APIs: Use
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(),ArgumentOutOfRangeException.ThrowIfLessThan(),ArgumentOutOfRangeException.ThrowIfGreaterThan(),ArgumentNullException.ThrowIfNull(),ArgumentException.ThrowIfNullOrEmpty()instead of manual checks Random.Shared: UseRandom.Sharedinstead ofnew Random()for thread-safe random number generationRandomNumberGenerator.Fill(): Use the static method instead ofRandomNumberGenerator.Create()+ disposal- Collection expressions: Use
[...]syntax for array initialization Span<T>: Usestackallocand span-based APIs to avoid allocations in hot paths- Expression-bodied members: Use for single-expression methods
Math.Clamp: Use instead of separateMath.Min/Math.Maxcalls- Generic constraints: Use
where T : struct, Enuminstead of runtimetypeof(T).IsEnumchecks - Pattern matching: Use
is null/is not nullinstead of== null/!= null - Nullable flow attributes: Use
[NotNullIfNotNull],[NotNullWhen],[MaybeNullWhen],[AllowNull]fromSystem.Diagnostics.CodeAnalysisto express conditional nullability contracts that the compiler can track through call sites — prefer these overT?return types when nullability depends on a specific argument
- Use
ArgumentOutOfRangeException.ThrowIf*guard APIs at method entry - Use
ArgumentExceptionfor invalid arguments that don't fit range checks - Include parameter names via
nameof()where applicable - Fail fast: throw exceptions immediately for invalid arguments
- Gather context: Read
RandomData.csand the test file to understand the full scope - Research patterns: Find existing usages of the code you're modifying
- Understand completely: Know the problem, side effects, and edge cases before coding
- Plan the approach: Choose the simplest solution that satisfies all requirements
- Minimize diffs: Change only what's necessary, preserve formatting and structure
- Preserve behavior: Don't break existing functionality or change semantics unintentionally
- Build incrementally: Run
dotnet buildafter each logical change to catch errors early - Test continuously: Run tests frequently to verify correctness
- Match style: Follow the patterns in surrounding code exactly
Before marking work complete, verify:
- Builds successfully:
dotnet build Exceptionless.RandomData.slnxexits with code 0 - All tests pass:
dotnet run --project test/Exceptionless.RandomData.Tests -f net8.0shows no failures - No new warnings: Check build output for new compiler warnings (warnings are treated as errors)
- API compatibility: Public API changes are intentional and backward-compatible when possible
- Breaking changes flagged: Clearly identify any breaking changes for review
- xUnit v3 with Microsoft Testing Platform as the test runner
- Test parallelization is disabled via
Properties/AssemblyInfo.cs
# All tests, both TFMs
dotnet run --project test/Exceptionless.RandomData.Tests -f net8.0
dotnet run --project test/Exceptionless.RandomData.Tests -f net10.0The test project uses <RootNamespace>Exceptionless.Tests</RootNamespace> to avoid a namespace conflict where the xUnit v3 MTP source generator creates a namespace Exceptionless.RandomData.Tests that shadows the Exceptionless.RandomData class. The test code uses using Xunit; and references RandomData.* methods directly since the Exceptionless namespace is accessible from within Exceptionless.Tests.
- README.md - Overview and usage examples
- NuGet Package