random - 需要帮助 - 使用 Autohotkey 脚本的简单随机数生成器

标签 random numbers generator autohotkey

我已经阅读了自动热键的文档,但对于编写脚本还是新手。我不断收到错误。

我想要一个非常简单的脚本 - 所以当我使用热键 CTRL-ALT-N - Autohotkey 会创建一个随机数:

3 位数字 - 十进制 - 8 位数字

第一组的第一个数字在 1 到 4 之间。

其余的可以完全随机。

在示例脚本之外,我尝试编辑一个已发布的脚本 - 但我做错了。如果有人可以提供帮助,我们将不胜感激!

输出应如下所示:314.99382028 第一个数字始终在 1 到 4 之间,其余数字是随机的,小数始终是第 4 个字符。

然后,它应该只是将号码粘贴到您当前在窗口中的任何位置 - 而不是弹出显示。

感谢任何可以快速浏览并提供帮助的人。

火箭

^!n:: ;<-- change this if you want a diff hotkey
Chars1 = 1234
Chars2 = 1234567890
Chars3 = .
str =
clipboard =
UpperRange = 3 ;<-- use all 3 character strings
len = 12 ;<-- number of characters in the number

; generate a new number
loop, %len%
{ random,x,1,%UpperRange% ;<-- selects the Character string
random,y,1,26 ;<-- selects the character in the string
if (x = 12) ; if numeric there are only 10 digits
}
{ random,y,1,10
StringMid,z,Chars%x%,1 ;<-- grab the selected letter
str = %str%%z% ;<-- and add it to the number string
}
clipboard = %str% ;<-- put the completed string on the clipboard
Clipwait ;<-- wait for the clipboard to accept the string`

然后粘贴到我的光标所在的位置 - 不知道该怎么做。

非常感谢您的帮助!

火箭

最佳答案

如果我理解正确的话,这应该可以完成工作:

^!n::
    SendInput, % "{LButton}" . RandomString(1,"1234") . RandomString(2) . "." . RandomString(8)
Return

RandomString(length,chars:="0123456789") {
    charsCount := StrLen(chars)
    Loop % length {
        Random, num, 1, % StrLen(chars)
        string .= SubStr(chars,num,1)
    }
    Return string
}

关于random - 需要帮助 - 使用 Autohotkey 脚本的简单随机数生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26564804/

相关文章:

random - 使用 math/rand 在 golang 中生成随机变量

swift - 本地通知徽章数量不超过一个

javascript - 为什么在 JavaScript 中收到我的个人推文 ID 号时,最后几位数字变为 "0"?

python - 具有固定队列大小或缓冲区的 multiprocessing.Pool.imap_unordered?

random - 生成随机字符串以附加到 UID

c++ - 如何包含 uniform_real_distribution 的最大值

java - 检查字符串标记是否包含字符串字符和字符串数字值

coffeescript - Yeoman 生成器 CoffeeScript 入口点

python - 当未产生该值时,有没有办法更新生成器循环条件?

go - rand.Reader读取时可能会报错?