mirror of
https://github.com/appgurueu/modlib.git
synced 2025-02-18 00:53:44 +01:00
Add text.random_bytes
This commit is contained in:
14
text.lua
14
text.lua
@ -145,5 +145,19 @@ function ibytes(text, start)
|
|||||||
return inextbyte, text, (start or 1) - 1
|
return inextbyte, text, (start or 1) - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function _random_bytes(count)
|
||||||
|
if count == 0 then return end
|
||||||
|
return math.random(0, 0xFF), _random_bytes(count - 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function random_bytes(
|
||||||
|
-- number, how many random bytes the string should have, defaults to 1
|
||||||
|
-- limited by stack size
|
||||||
|
count
|
||||||
|
)
|
||||||
|
count = count or 1
|
||||||
|
return string.char(_random_bytes(count))
|
||||||
|
end
|
||||||
|
|
||||||
-- Export environment
|
-- Export environment
|
||||||
return _ENV
|
return _ENV
|
||||||
|
Reference in New Issue
Block a user