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 e2700d2 commit 0b5cdeb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 随机字符串/随机大小写字母.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function rndLetter(num)
local ret = ""
pcall(function()
for var = 1,num do
if math.random()>0.5 then
ret = ret..string.char(math.random(65,90))
else
ret = ret..string.char(math.random(97,122))
end
end
end)
return ret
end

--用法
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1,6))) --设置随机种子
for var = 1,5 do
nLog(rndLetter(10)) --生成一个 10 位随机大小写字母的字符串
end

0 comments on commit 0b5cdeb

Please sign in to comment.