Skip to content

Commit 3a2e283

Browse files
authored
Update util.lua
Add a shuffle string feature, for potential future use.
1 parent 5597701 commit 3a2e283

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/prometheus/util.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ local function shuffle(tb)
108108
end
109109
return tb
110110
end
111+
local function shuffle_string(str)
112+
local len = #str
113+
local t = {}
114+
for i = 1, len do
115+
t[i] = string.sub(str, i, i)
116+
end
117+
for i = 1, len do
118+
local j = math.random(i, len)
119+
t[i], t[j] = t[j], t[i]
120+
end
121+
return table.concat(t)
122+
end
111123

112124
local function readDouble(bytes)
113125
local sign = 1
@@ -255,6 +267,7 @@ return {
255267
chararray = chararray,
256268
keys = keys,
257269
shuffle = shuffle,
270+
shuffle_string = shuffle_string,
258271
readDouble = readDouble,
259272
writeDouble = writeDouble,
260273
readU16 = readU16,
@@ -270,4 +283,4 @@ return {
270283
toBits = toBits,
271284
bytesToString = bytesToString,
272285
readonly = readonly,
273-
}
286+
}

0 commit comments

Comments
 (0)