我想知道是否有可能运行一行代码,然后在一组其他行之间随机化,例如;
1::(我希望此函数在2-5之间随机选择并运行该行)
2::enter code here
3::enter code here
4::enter code here
5::enter code here
发布于 2020-12-11 10:20:26
这看起来像是AHK 的工作
与其移动到特定行,不如将代码保存在不同的标签中。为了确定随机性,使用AHK的Random函数随机生成一个数字。然后,使用switch语句确定要转到先前编码的标签并运行。
代码:
;Generate a random number from 1 to 5 inclusive
Random, rand, 1, 5
;Use a switch statement to go to the corresponding label
Switch rand{
case 1:goto, One
case 2:goto, Two
case 3:goto, Three
case 4:goto, Four
case 5:goto, Five
}
return
One:
MsgBox This is label "One"
;Insert code in between the colon and the return
return
Two:
MsgBox This is label "Two"
;Insert code in between the colon and the return
return
Three:
MsgBox This is label "Three"
;Insert code in between the colon and the return
return
Four:
MsgBox This is label "Four"
;Insert code in between the colon and the return
return
Five:
MsgBox This is label "Five"
;Insert code in between the colon and the return
returnhttps://stackoverflow.com/questions/65244760
复制相似问题