gpt4 book ai didi

powershell - Get-Random和random有什么区别

转载 作者:行者123 更新时间:2023-12-02 23:12:27 25 4
gpt4 key购买 nike

在尝试一个小的脚本时,它突然变得慢很多。我意识到我已经用random代替了get-random,假设它是一个别名。

比较以下输出:

measure-command { (0..1000) | % { get-random } }
...
Seconds : 0
Milliseconds : 86
...


measure-command { (0..1000) | % { random } }
...
Seconds : 44
Milliseconds : 192
...

看来 randomget-random慢约50倍。似乎 random而不是get-random别名,即使看起来参数相同。 get-alias randomget-command random均返回错误,表明找不到 random

TL; DR
random不是 get-random,这是什么?

最佳答案

randomGet-Random
当PowerShell无法将一字命令解析为函数/别名/可执行文件时,它的作用就像隐含了Get动词一样。

这也适用于任何其他Get-* cmdlet。在powershell.exe中尝试其中的一些:

item .
childitem $env:USERPROFILE
help random
content $env:SystemRoot\System32\drivers\etc\hosts

我实际上不确定帮助文件中是否提到了这一点,但是自PowerShell版本1.0以来就是这种情况,如2006年的 "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 command process will behave in exactly the same manner as get-process

关于powershell - Get-Random和random有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34032554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com