- local fp = io.open("/dev/urandom")
- local chunk = { fp:read(bytes):byte(1, bytes) }
- fp:close()
-
- local hex = ""
-
- local pattern = "%02X"
- for i, byte in ipairs(chunk) do
- hex = hex .. pattern:format(byte)
- end
-
- return hex
+ local rand = luci.fs.readfile("/dev/urandom", bytes)
+ return rand and nixio.bin.hexlify(rand)