Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

(refactor) randomInt & randomStr #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions modules/utils/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ function zf.log(type, message)
end

function zf.randomStr(length)
local charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
if length <= 0 then return '' end
return QBShared.RandomStr(length - 1) .. StringCharset[math.random(1, #StringCharset)]
local str = ""
for i = 1, length do
local rand = math.random(#charset)
str = str .. string.sub(charset, rand, rand)
end
return str
end

function zf.randomInt(length)
if length <= 0 then return '' end
return QBShared.RandomInt(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
local min = 10^(length-1)
local max = 10^length - 1
return math.random(min, max)
end

function zf.splitStr(str, delimiter)
Expand Down Expand Up @@ -95,4 +103,4 @@ function zf.getProgressColor(pourcentage, inverted)
if pourcentage > 50 then return '#f4a261' end
if pourcentage > 30 then return '#e9c46a' end
if pourcentage > 0 then return '#2a9d8f' end
end
end