Use the default RNG factory inside an existing using block

Proprietary

Replace parameterless RNGCryptoServiceProvider construction in using (var rng = new ...) with RandomNumberGenerator.Create(), retaining the scope and disposal. Require all references to be bound byte-array GetBytes/GetNonZeroBytes calls in the block. Preserve arguments, evaluation and null failures. Skip provider options, escapes, other members, captures, async/iterators and conditional snapshots. Opt-in modern-.NET compatibility port.

OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net6.UseScopedRandomNumberGenerator
mod run . --recipe=OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net6.UseScopedRandomNumberGenerator

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.