首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AHK随机函数题,如何随机化调用哪个阶函数

AHK随机函数题,如何随机化调用哪个阶函数
EN

Stack Overflow用户
提问于 2020-12-11 09:57:09
回答 1查看 205关注 0票数 0

我想知道是否有可能运行一行代码,然后在一组其他行之间随机化,例如;

1::(我希望此函数在2-5之间随机选择并运行该行)

2::enter code here

3::enter code here

4::enter code here

5::enter code here

EN

回答 1

Stack Overflow用户

发布于 2020-12-11 10:20:26

这看起来像是AHK 的工作

与其移动到特定行,不如将代码保存在不同的标签中。为了确定随机性,使用AHK的Random函数随机生成一个数字。然后,使用switch语句确定要转到先前编码的标签并运行。

代码:

代码语言:javascript
复制
;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
return
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65244760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档