aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2021-10-08 15:40:13 +0200
committerBond_009 <bond.009@outlook.com>2021-10-08 15:40:13 +0200
commitd05062fec06ecba1049beefffe8d8f521d3e1881 (patch)
tree8a90dd591a2bc87cdb4f76b6691590cc2072fc3f
parent556ef5f157cc1bb3acbc7e1ae3edfa28333914cc (diff)
Use new Random.Shared instead of creating new instances
-rw-r--r--Emby.Server.Implementations/Dto/DtoService.cs2
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs3
-rw-r--r--Jellyfin.Api/Controllers/MediaInfoController.cs2
-rw-r--r--tests/Jellyfin.Extensions.Tests/ShuffleExtensionsTests.cs4
4 files changed, 4 insertions, 7 deletions
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs
index 74400b512..ad76f3d6d 100644
--- a/Emby.Server.Implementations/Dto/DtoService.cs
+++ b/Emby.Server.Implementations/Dto/DtoService.cs
@@ -420,7 +420,7 @@ namespace Emby.Server.Implementations.Dto
// Just return something so that apps that are expecting a value won't think the folders are empty
if (folder is ICollectionFolder || folder is UserView)
{
- return new Random().Next(1, 10);
+ return Random.Shared.Next(1, 10);
}
return folder.GetChildCount(user);
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs
index b2e555c7d..08ed1a32a 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunManager.cs
@@ -150,8 +150,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
if (!_lockkey.HasValue)
{
- var rand = new Random();
- _lockkey = (uint)rand.Next();
+ _lockkey = (uint)Random.Shared.Next();
}
var lockKeyValue = _lockkey.Value;
diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs
index 96ef2d678..b422eb78c 100644
--- a/Jellyfin.Api/Controllers/MediaInfoController.cs
+++ b/Jellyfin.Api/Controllers/MediaInfoController.cs
@@ -316,7 +316,7 @@ namespace Jellyfin.Api.Controllers
byte[] buffer = ArrayPool<byte>.Shared.Rent(size);
try
{
- new Random().NextBytes(buffer);
+ Random.Shared.NextBytes(buffer);
return File(buffer, MediaTypeNames.Application.Octet);
}
finally
diff --git a/tests/Jellyfin.Extensions.Tests/ShuffleExtensionsTests.cs b/tests/Jellyfin.Extensions.Tests/ShuffleExtensionsTests.cs
index c72216d94..a73cfb078 100644
--- a/tests/Jellyfin.Extensions.Tests/ShuffleExtensionsTests.cs
+++ b/tests/Jellyfin.Extensions.Tests/ShuffleExtensionsTests.cs
@@ -5,13 +5,11 @@ namespace Jellyfin.Extensions.Tests
{
public static class ShuffleExtensionsTests
{
- private static readonly Random _rng = new Random();
-
[Fact]
public static void Shuffle_Valid_Correct()
{
byte[] original = new byte[1 << 6];
- _rng.NextBytes(original);
+ Random.Shared.NextBytes(original);
byte[] shuffled = (byte[])original.Clone();
shuffled.Shuffle();