Skip to content

RandomNumberGenerator: .NET 10, GetHexString and GetString helpers, exclusive-bound range tests - #2268

Merged
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/96155-csharp-create-cryptographic-numbers-with-randomnumbergenerator
Oct 6, 2026
Merged

vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/96155-csharp-create-cryptographic-numbers-with-randomnumbergenerator

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Updates the sample for "RandomNumberGenerator in C#: Secure Random Numbers" (https://code-maze.com/csharp-create-cryptographic-numbers-with-randomnumbergenerator/).

Folder: dotnet-base-libraries/CryptographyRandomNumberGenerator only.

  • App and Tests retargeted from net7.0 to net10.0.
  • Packages, re-queried on NuGet 2026-10-04: BenchmarkDotNet 0.15.8, Microsoft.NET.Test.Sdk 18.10.1, xunit 2.9.3, xunit.runner.visualstudio 4.0.0, coverlet.collector 10.1.0. Test framework unchanged (xunit).
  • New helpers GenerateHexKey (RandomNumberGenerator.GetHexString) and GenerateToken (RandomNumberGenerator.GetString), both .NET 8, with one test each.
  • The two range tests asserted Assert.InRange(value, min, max), which is inclusive at both ends, while GetInt32 and Random.Next exclude the upper bound. They now assert max - 1, so a return value of 100 would fail them.

Local run: SDK 10.0.302, runtime .NET 10.0.10. Build 0 warnings, 5 of 5 tests passed, no vulnerable packages (including transitive). The benchmark was re-run in Release for the article.

…tring helpers, fix range tests

- App and Tests move from net7.0 to net10.0
- BenchmarkDotNet 0.15.8, Microsoft.NET.Test.Sdk 18.10.1, xunit 2.9.3,
  xunit.runner.visualstudio 4.0.0, coverlet.collector 10.1.0
- Add GenerateHexKey and GenerateToken (.NET 8 GetHexString and GetString) with tests
- The range tests now assert maxValue - 1: GetInt32 and Random.Next exclude the upper
  bound, and Assert.InRange is inclusive, so the old assertion passed for 100
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 9dbf944 into CodeMazeBlog:main Oct 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant