replace lua Random implementation with usertype

This commit is contained in:
MihailRis
2025-09-25 23:53:11 +03:00
parent 3a40162f1e
commit 088bf63f3f
7 changed files with 115 additions and 38 deletions
+30 -1
View File
@@ -669,4 +669,33 @@ end
bit.compile = require "core:bitwise/compiler"
bit.execute = require "core:bitwise/executor"
random.Random = require "core:internal/random_generator"
function __vc_create_random_methods(random_methods)
local index = 1
local buffer = nil
local buffer_size = 64
function random_methods:bytes(n)
local bytes = Bytearray(n)
for i=1,n do
bytes[i] = self:random(255)
end
return bytes
end
function random_methods:random(a, b)
if not buffer or index > #buffer then
buffer = self:generate(buffer_size)
index = 1
end
local value = buffer[index]
if b then
value = math.floor(value * (b - a + 1) + a)
elseif a then
value = math.floor(value * a + 1)
end
index = index + 4
return value
end
return random_methods
end