Skip to content

Commit

Permalink
Create 自定义字符串随机.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
chudongjingling authored May 22, 2020
1 parent e8bfac9 commit e2700d2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 随机字符串/自定义字符串随机.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function randomStr(str, num)
local ret =''
for i = 1, num do
local rchr = math.random(1, string.len(str))
ret = ret .. string.sub(str, rchr, rchr)
end
return ret
end

--用法
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6))) --设置随机种子
for var = 1,5 do
s = randomStr("abcdefghijklmnopqrstuvwxyz", 6) --生成 6 位随机字母
nLog(s)
end

0 comments on commit e2700d2

Please sign in to comment.