几天来,我一直试图在罗技游戏软件(LGS)脚本中找到一种随机数字的制作方法。我知道有
math.random()
math.randomseed()
但问题是,我需要一个更改值作为种子,其他解决方案是添加一个在LGS脚本中不支持的os.time or tick() or GetRunningTime
内容。我希望某个善良的灵魂能通过给我展示一段代码来帮助我,这些代码可以产生纯粹的随机数。因为,我不想要伪随机数,因为它们只是随机的一次。每次它运行命令时,我都需要它是随机的。就像我将math.randomI()循环100次一样,每次都会显示不同的数字。提前感谢!
发布于 2019-03-19 07:32:05
拥有不同的种子并不能保证你每次都有不同的号码。它只会确保每次运行代码时都不会有相同的随机序列。
一个简单的,也是最有可能的足够的解决方案是使用鼠标位置作为一个随机种子。
在一个4K屏幕上,有超过800万种不同的随机种子,很难在合理的时间内到达相同的坐标。除非您的游戏要求在运行脚本时一遍又一遍地单击相同的位置。
发布于 2019-03-19 08:28:26
这个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
https://stackoverflow.com/questions/55233912
复制相似问题