【紧急】写一个算法,随机生成1个由5位数组成的字符串啊,每位数均
lua吧
全部回复
仅看楼主
level 1
【紧急】写一个算法,随机生成1个由5位数组成的字符串啊,每位数均可取0-9
2010年04月21日 06点04分 1
level 0
---[[ 使用5个随机数组合成随即字符串
math.randomseed(os.time());
local t1 = math.random(0,9)
local t2 = math.random(0,9)
local t3 = math.random(0,9)
local t4 = math.random(0,9)
local t5 = math.random(0,9)
str = tostring(t1) .. tostring(t2) .. tostring(t3) .. tostring(t4) .. tostring(t5)
print(str)
--]]
2010年06月17日 03点06分 2
level 1
[超高兴].
2010年07月17日 15点07分 3
level 1
ruby 版本:
print("%05d",rand(100000))
2011年06月07日 07点06分 4
level 1
写错了,是 printf
2011年06月10日 02点06分 5
level 7
lua也一样:
print(string.format("%05d", math.random(0, 99999)))
2011年06月22日 08点06分 6
1