DCSIMG
Random - Shay Levy

Shay Levy

If you repeat it, PowerShell it!

Browse by Tags

All Tags » Random (RSS)
Randomizing collections: one-liners
I found a cool way HERE to shuffle/reorder array elements without using the random class. Generally you provide Sort-Object an object property to sort on, only now the property is in the form of a Globally Globally Unique Identifier (GUID) , which is a random generated 128-bit integer. PS > 1..5 | sort-object { [guid]::newGuid() } 2 5 3 1 4 To select one or more random objects from the collection, pipe the above to Select-Object and use the -First (or -Last) parameter: PS > 1..5 | sort-object...