2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00
koreader/frontend/random.lua
NiLuJe 7210fb478d
Faster blitting @ BB8/BBRGB32 when no processing is needed (#4847)
* Pickup the eponymous blitting performance tweaks from koreader/koreader-base#878
* Cleanup BitOpts usage (require & cache)
* Unify oddness checks (MOD -> AND)
* Enforce the native Portrait orientation on Kobo (except @ 16bpp, i.e., KSM w/ 8bpp swap disabled), to allow for faster blitting when unrotted.
* Switch CRe BB to 32BPP on color screens
* Minor cleanups
2019-03-27 22:50:44 +01:00

35 lines
982 B
Lua

--- A set of functions to extend math.random and math.randomseed.
local bit = require("bit")
local random = {}
--- Uses current time as seed to randomize.
function random.seed()
math.randomseed(os.time())
end
random.seed()
--- Returns a UUID (v4, random).
function random.uuid(with_dash)
local array = {}
for i = 1, 16 do
table.insert(array, math.random(256) - 1)
end
-- The 13th character should be 4.
array[7] = bit.band(array[7], 79)
array[7] = bit.bor(array[7], 64)
-- The 17th character should be 8 / 9 / a / b.
array[9] = bit.band(array[9], 191)
array[9] = bit.bor(array[9], 128)
if with_dash then
return string.format("%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
unpack(array))
else
return string.format("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
unpack(array))
end
end
return random