diff --git a/src/Playground/Benchmark/OldTests.cs b/src/Playground/Benchmark/OldTests.cs index faa25db..4a562b9 100644 --- a/src/Playground/Benchmark/OldTests.cs +++ b/src/Playground/Benchmark/OldTests.cs @@ -125,7 +125,7 @@ public static void ShowBottomSegments(WriteAheadLogMode mode, int count) var iterate = false; if (iterate) { - var random = new Random(); + var random = Random.Shared; Parallel.For(0, 750000, (i) => { var key = random.Next(0, 999_999_999); diff --git a/src/Playground/DeadlockFinder.cs b/src/Playground/DeadlockFinder.cs index dd9214f..fe77124 100644 --- a/src/Playground/DeadlockFinder.cs +++ b/src/Playground/DeadlockFinder.cs @@ -20,7 +20,7 @@ void TreeLoop(int taskNo) const int upsertLogFrequency = 1_000_000; const int iterationLogFrequency = 10_000_000; const int iterationYieldFrequency = 1000; - var rand = new Random(); + var rand = Random.Shared; void resetTree() { diff --git a/src/ZoneTree.UnitTests/AtomicUpdateTests.cs b/src/ZoneTree.UnitTests/AtomicUpdateTests.cs index 156f681..050f85d 100644 --- a/src/ZoneTree.UnitTests/AtomicUpdateTests.cs +++ b/src/ZoneTree.UnitTests/AtomicUpdateTests.cs @@ -29,7 +29,7 @@ public void IntIntAtomicIncrement(WriteAheadLogMode walMode) } data.Maintenance.MoveMutableSegmentForward(); data.Maintenance.StartMergeOperation().Join(); - var random = new Random(); + var random = Random.Shared; var off = -1; Parallel.For(0, 1001, (x) => { @@ -100,7 +100,7 @@ public void IntIntAtomicIncrementForBTree(WriteAheadLogMode walMode) { data.Upsert(i, i + i); } - var random = new Random(); + var random = Random.Shared; var off = -1; Parallel.For(0, 1001, (x) => { @@ -166,7 +166,7 @@ public void IntIntMutableSegmentOnlyAtomicIncrement(WriteAheadLogMode walMode) { data.Upsert(i, i + i); } - var random = new Random(); + var random = Random.Shared; var off = -1; Parallel.For(0, 1001, (x) => { @@ -228,7 +228,7 @@ public void IntIntMutableSegmentSeveralUpserts(WriteAheadLogMode walMode) .ConfigureWriteAheadLogOptions(x => x.WriteAheadLogMode = walMode) .OpenOrCreate(); var n = 1000; - var random = new Random(); + var random = Random.Shared; Parallel.For(0, 1000, (x) => { try diff --git a/src/ZoneTree.UnitTests/ExceptionlessTransactionTests.cs b/src/ZoneTree.UnitTests/ExceptionlessTransactionTests.cs index 133eeaa..54987c1 100644 --- a/src/ZoneTree.UnitTests/ExceptionlessTransactionTests.cs +++ b/src/ZoneTree.UnitTests/ExceptionlessTransactionTests.cs @@ -82,7 +82,7 @@ public async Task TransactionWithFluentAPI(int compactionThreshold) zoneTree.Maintenance.TransactionLog.CompactionThreshold = compactionThreshold; - var random = new Random(); + var random = Random.Shared; await Parallel.ForEachAsync(Enumerable.Range(0, 1000), async (x, cancel) => { using var transaction = diff --git a/src/ZoneTree.UnitTests/IteratorTests.cs b/src/ZoneTree.UnitTests/IteratorTests.cs index 1501bc6..889864d 100644 --- a/src/ZoneTree.UnitTests/IteratorTests.cs +++ b/src/ZoneTree.UnitTests/IteratorTests.cs @@ -240,7 +240,7 @@ public void IntIntIteratorParallelInserts() if (Directory.Exists(dataPath)) Directory.Delete(dataPath, true); - var random = new Random(); + var random = Random.Shared; var insertCount = 100000; var iteratorCount = 1000; @@ -289,7 +289,7 @@ public void IntIntReverseIteratorParallelInserts(bool reverse) if (Directory.Exists(dataPath)) Directory.Delete(dataPath, true); - var random = new Random(); + var random = Random.Shared; var insertCount = 1000000; var iteratorCount = 1000; @@ -352,7 +352,7 @@ public void IntIntSnapshotIteratorParallelInserts() if (Directory.Exists(dataPath)) Directory.Delete(dataPath, true); - var random = new Random(); + var random = Random.Shared; var insertCount = 100000; var iteratorCount = 1000; @@ -512,7 +512,7 @@ public void SeekIteratorsAfterMerge( if (merge) zoneTree.Maintenance.StartMergeOperation()?.Join(); - var random = new Random(); + var random = Random.Shared; DoPrefixSearch(zoneTree, list, random); zoneTree.Maintenance.DiskSegment.InitSparseArray(100); DoPrefixSearch(zoneTree, list, random); @@ -604,7 +604,7 @@ public void SeekIteratorsAfterMergeReload( x.MaximumRecordCount = maximumRecordCount; }) .Open(); - var random = new Random(); + var random = Random.Shared; DoPrefixSearch(zoneTree, list, random); zoneTree.Maintenance.DiskSegment.InitSparseArray(100); DoPrefixSearch(zoneTree, list, random); diff --git a/src/ZoneTree.UnitTests/SafeBplusTreeTests.cs b/src/ZoneTree.UnitTests/SafeBplusTreeTests.cs index 9054572..ad5c4a6 100644 --- a/src/ZoneTree.UnitTests/SafeBplusTreeTests.cs +++ b/src/ZoneTree.UnitTests/SafeBplusTreeTests.cs @@ -22,13 +22,13 @@ public void BTreeIteration(BTreeLockMode lockMode) tree.TryInsert(i, i + i, out _); var iterator = new BTreeSeekableIterator(tree); - var j = 0; + var j = 0; while (iterator.Next()) { Assert.That(iterator.CurrentKey, Is.EqualTo(j)); Assert.That(iterator.CurrentValue, Is.EqualTo(j + j)); ++j; - } + } iterator.SeekEnd(); j = n - 1; @@ -92,7 +92,7 @@ public void BTreeLowerOrEqualBound(BTreeLockMode lockMode) Assert.That(GetLastNodeSmallerOrEqual(iterator, 4), Is.EqualTo(3)); Assert.That(GetLastNodeSmallerOrEqual(iterator, 3), Is.EqualTo(3)); Assert.Throws( - () => GetLastNodeSmallerOrEqual(iterator ,- 1)); + () => GetLastNodeSmallerOrEqual(iterator, -1)); Assert.That(GetLastNodeSmallerOrEqual(iterator, 10), Is.EqualTo(9)); Assert.That(GetLastNodeSmallerOrEqual(iterator, 9), Is.EqualTo(9)); Assert.That(GetLastNodeSmallerOrEqual(iterator, 1), Is.EqualTo(1)); @@ -135,7 +135,7 @@ int GetFirstNodeGreaterOrEqual(BTreeSeekableIterator iterator, int key [TestCase(BTreeLockMode.NodeLevelMonitor)] public void BTreeIteratorParallelInserts(BTreeLockMode lockMode) { - var random = new Random(); + var random = Random.Shared; var insertCount = 100000; var iteratorCount = 1000; @@ -190,7 +190,7 @@ public void BTreeIteratorParallelInserts(BTreeLockMode lockMode) [TestCase(BTreeLockMode.NodeLevelMonitor)] public void BTreeReverseIteratorParallelInserts(BTreeLockMode lockMode) { - var random = new Random(); + var random = Random.Shared; var insertCount = 100000; var iteratorCount = 1550; @@ -203,7 +203,7 @@ public void BTreeReverseIteratorParallelInserts(BTreeLockMode lockMode) { var key = random.Next(); tree.AddOrUpdate(key, - AddOrUpdateResult (ref int x) => + AddOrUpdateResult (ref int x) => { x = key + key; return AddOrUpdateResult.ADDED; @@ -253,7 +253,7 @@ public void BTreeReverseIteratorParallelInserts(BTreeLockMode lockMode) [TestCase(BTreeLockMode.NodeLevelMonitor)] public void IntIntDuplicateRecords(BTreeLockMode lockMode) { - var random = new Random(); + var random = Random.Shared; var insertCount = 1000000; var iteratorCount = 1000; @@ -297,7 +297,7 @@ public void IntIntDuplicateRecords(BTreeLockMode lockMode) [TestCase(BTreeLockMode.NodeLevelMonitor)] public void IntIntDuplicateReverseRecords(BTreeLockMode lockMode) { - var random = new Random(); + var random = Random.Shared; var insertCount = 1000000; var iteratorCount = 1000; diff --git a/src/ZoneTree/Segments/MultiPart/MultiPartDiskSegmentCreator.cs b/src/ZoneTree/Segments/MultiPart/MultiPartDiskSegmentCreator.cs index 3f2d107..2511c8a 100644 --- a/src/ZoneTree/Segments/MultiPart/MultiPartDiskSegmentCreator.cs +++ b/src/ZoneTree/Segments/MultiPart/MultiPartDiskSegmentCreator.cs @@ -34,7 +34,7 @@ public sealed class MultiPartDiskSegmentCreator : IDiskSegmentCrea readonly List PartValues = new(); - readonly Random Random = new(); + readonly Random Random = Random.Shared; TKey LastAppendedKey;