我已经尝试了几天尝试在Logitech游戏软件(LGS)脚本中找到一种随机数的方法。我知道有
math.random()
math.randomseed()
但是,我需要一个更改种子的值,而其他解决方案是添加LGS脚本中不支持的os.time or tick() or GetRunningTime
内容。我希望某种善良的灵魂可以通过向我展示一块纯粹随机数来帮助我。因为我不想要伪随机数,因为它们仅是随机的。每次运行命令时,我都需要它是随机。就像我循环the Math.randomi()一百次,每次都会显示一个不同的数字。预先感谢!
拥有不同的种子不会每次都有不同的数字。它只会确保每次运行代码时都不会有相同的随机序列。
一种简单且最有可能的解决方案将是将鼠标位置用作随机种子。
在4K屏幕上,超过800万种不同的随机种子,并且在合理的时间内您不太可能达到相同的坐标。除非您的游戏要求在运行该脚本时一遍又一遍地单击相同的位置。
此RNG从所有事件中接收熵。
初始RNG状态在每次运行中都会有所不同。
只需在代码中使用random
而不是math.random
即可。
local mix
do
local K53 = 0
local byte, tostring, GetMousePosition, GetRunningTime = string.byte, tostring, GetMousePosition, GetRunningTime
function mix(data1, data2)
local x, y = GetMousePosition()
local tm = GetRunningTime()
local s = tostring(data1)..tostring(data2)..tostring(tm)..tostring(x * 2^16 + y).."@"
for j = 2, #s, 2 do
local A8, B8 = byte(s, j - 1, j)
local L36 = K53 % 2^36
local H17 = (K53 - L36) / 2^36
K53 = L36 * 126611 + H17 * 505231 + A8 + B8 * 3083
end
return K53
end
mix(GetDate())
end
local function random(m, n) -- replacement for math.random
local h = mix()
if m then
if not n then
m, n = 1, m
end
return m + h % (n - m + 1)
else
return h * 2^-53
end
end
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
mix(event, arg) -- this line adds entropy to RNG
-- insert your code here:
-- if event == "MOUSE_BUTTON_PRESSED" and arg == 3 then
-- local k = random(5, 10)
-- ....
-- end
end