You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a -Shuffle switch to Get-Random for convenient collection shuffling #11022
Issue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
Get-Random currently requires you to specify a -Count argument in order to extract a random subset from an input collection.
Sometimes you want to shuffle an input collection, i.e. to return all input objects, in randomized order, and it would be nice to be able to express that intent directly, without having to provide a -Count (which may not even be known; you can work around that with -Count ([int]::MaxValue), but that is awkward).
To that end, a new -Shuffle parameter could be introduced:
What should happen if one had set both -Count and -Shuffle parameters? Should the command return just random objects and ignore the -Shuffle switch or return the entire collection, in randomized order, despite the -Count? Another possible way is to throw an error, but I don't think it is a good solution.
I think the most elegant solution would simply be to put the -Shuffle parameter in a completely different parameter set, so that it can't be used with -Count, via the Parameter attribute:
Issue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues
Activity
eugenesmlv commentedon Nov 10, 2019
I'm working on this one.
eugenesmlv commentedon Nov 13, 2019
What should happen if one had set both
-Countand-Shuffleparameters? Should the command return just random objects and ignore the-Shuffleswitch or return the entire collection, in randomized order, despite the-Count? Another possible way is to throw an error, but I don't think it is a good solution.vexx32 commentedon Nov 13, 2019
I think the most elegant solution would simply be to put the -Shuffle parameter in a completely different parameter set, so that it can't be used with -Count, via the
Parameterattribute:Then when determining your code path you can use
switch (ParameterSetName)to determine which code path to take. 🙂