< Summary

Information
Class: MyNet.Generator.Facade.RandomGenerator
Assembly: MyNet.Generator
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Generator/Facade/RandomGenerator.cs
Tag: 323_28699572109
Line coverage
87%
Covered lines: 7
Uncovered lines: 1
Coverable lines: 8
Total lines: 43
Line coverage: 87.5%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_Current()100%11100%
set_Current(...)50%22100%
get_Instance()100%210%
Reset()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Generator/Facade/RandomGenerator.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="RandomGenerator.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Diagnostics.CodeAnalysis;
 9using System.Threading;
 10
 11namespace MyNet.Generator.Facade;
 12
 13/// <summary>
 14/// Provides a thread-safe and lock-free random number generator instance.
 15/// </summary>
 16[SuppressMessage("Security", "CA5394:Do not use insecure randomness", Justification = "Using System.Random.Shared for no
 17public static class RandomGenerator
 18{
 519    private static IRandomGenerator _current = new DefaultRandomGenerator(new SystemRandomSource());
 20
 21    /// <summary>
 22    /// Gets or sets the service used by static Random* helpers.
 23    /// </summary>
 24    public static IRandomGenerator Current
 25    {
 682726        get => Volatile.Read(ref _current);
 1227        set => Volatile.Write(ref _current,
 1228            value ?? throw new ArgumentNullException(nameof(value)));
 29    }
 30
 31    /// <summary>
 32    /// Gets the underlying shared random instance.
 33    /// </summary>
 034    public static Random Instance => Random.Shared;
 35
 36    /// <summary>
 37    /// Resets static random helpers to the default service implementation.
 38    /// </summary>
 339    public static void Reset() => Volatile.Write(
 340        ref _current,
 341        new DefaultRandomGenerator(new SystemRandomSource()));
 42}
 43