Respect -Shuffle:$false in Get-Random (#26457)

This commit is contained in:
yotsuda
2025-11-17 08:36:48 +05:00
committed by GitHub
parent 250e18cc9b
commit 77f1d99568
2 changed files with 7 additions and 1 deletions
@@ -488,7 +488,7 @@ namespace Microsoft.PowerShell.Commands
{
if (EffectiveParameterSet == MyParameterSet.RandomListItem)
{
if (ParameterSetName == ShuffleParameterSet)
if (Shuffle)
{
// this allows for $null to be in an array passed to InputObject
foreach (object item in InputObject ?? _nullInArray)
@@ -162,6 +162,12 @@ Describe "Get-Random" -Tags "CI" {
$randomNumber | Should -BeIn 1, 2, 3, 5, 8, 13
}
It "Should return a single random item when -Shuffle:`$false is used" {
$randomNumber = Get-Random -InputObject 1, 2, 3, 5, 8, 13 -Shuffle:$false
$randomNumber.Count | Should -Be 1
$randomNumber | Should -BeIn 1, 2, 3, 5, 8, 13
}
It "Should return for a string collection " {
$randomNumber = Get-Random -InputObject "red", "yellow", "blue"
$randomNumber | Should -Be ("red" -or "yellow" -or "blue")