Reputation: 1933
While experimenting with a small script, it suddenly became much slower. I realized that I had substituted random
for get-random
, assuming it was an alias.
Compare the following outputs:
measure-command { (0..1000) | % { get-random } }
...
Seconds : 0
Milliseconds : 86
...
vs
measure-command { (0..1000) | % { random } }
...
Seconds : 44
Milliseconds : 192
...
It appears that random
is ~50x slower than get-random
. It appears that random
is not an alias of get-random
, even though it seems to the same parameters. get-alias random
and get-command random
both return an error that random
cannot be not found.
TL;DR
random
is not get-random
, what is it?
Upvotes: 2
Views: 269
Reputation: 174525
random
is Get-Random
When PowerShell cannot resolve a 1-word command to a function/alias/executable, it acts as if the Get
verb is implied.
This works for any other Get-*
cmdlet as well. Try some of these in powershell.exe
:
item .
childitem $env:USERPROFILE
help random
content $env:SystemRoot\System32\drivers\etc\hosts
I'm not actually sure this is mentioned in the help files, but it has been the case since PowerShell version 1.0, as described in the 2006 book "Monad (AKA. PowerShell): Introducing the MSH Command Shell and Language":
All nouns have a default verb,
get
, which is assumed if no verb is given. In other words, the commandprocess
will behave in exactly the same manner asget-process
Upvotes: 4