Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions PolyShim.Tests/Net60/RandomTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.Net60;

public class RandomTests
{
[Fact]
public void Shared_Test()
{
// Act
var value = Random.Shared.Next(1, 100);

// Assert
value.Should().BeInRange(1, 100);
}
}
24 changes: 24 additions & 0 deletions PolyShim/Net60/Random.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// The following comment is required to instruct analyzers to skip this file
// <auto-generated/>

#if (NETCOREAPP && !NET6_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD)
#nullable enable
// ReSharper disable RedundantUsingDirective
// ReSharper disable CheckNamespace
// ReSharper disable InconsistentNaming
// ReSharper disable PartialTypeWithSinglePart

using System;

internal static partial class PolyfillExtensions
{
[ThreadStatic]
private static Random? _threadRandom;

extension(Random)
{
// https://learn.microsoft.com/dotnet/api/system.random.shared
public static Random Shared => _threadRandom ??= new Random();
}
}
#endif
Loading