mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Make use of the new Random.Shared property (#18417)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user