Make use of the new Random.Shared property (#18417)

This commit is contained in:
Berkan Diler
2023-06-12 17:31:04 -07:00
committed by GitHub
parent ba0de3b4fe
commit 0f53e80335
4 changed files with 4 additions and 6 deletions
@@ -797,7 +797,7 @@ $result
if (Wait)
{
_activityId = (new Random()).Next();
_activityId = Random.Shared.Next();
if (_timeout == -1 || _timeout >= int.MaxValue / 1000)
{
_timeoutInMilliseconds = int.MaxValue;
@@ -892,7 +892,7 @@ namespace System.Management.Automation.Host
{
// System transcripts can have high contention. Do exponential back-off on writing
// if needed.
int delay = new Random().Next(10) + 1;
int delay = Random.Shared.Next(10) + 1;
bool written = false;
while (!written)
@@ -1466,7 +1466,7 @@ namespace System.Management.Automation
// But split the segments into random sizes (10k + between 0 and 10kb extra)
// so that attackers can't creatively force their scripts to span well-known
// segments (making simple rules less reliable).
int segmentSize = 10000 + (new Random()).Next(10000);
int segmentSize = 10000 + Random.Shared.Next(10000);
int segments = (int)Math.Floor((double)(scriptBlockText.Length / segmentSize)) + 1;
int currentLocation = 0;
int currentSegmentSize = 0;
@@ -210,9 +210,7 @@ namespace Microsoft.PowerShell.Commands
_exceptions = new Dictionary<string, UpdatableHelpExceptionContext>();
_helpSystem.OnProgressChanged += HandleProgressChanged;
Random rand = new Random();
activityId = rand.Next();
activityId = Random.Shared.Next();
}
#endregion