没有错误消息,所以我不知道出了什么问题
no error messeage so i don't know what is wrong
我正在编写代码并且我 运行 它但是没有用。它没有向我显示错误消息,所以我不知道出了什么问题。谁能解决这个问题?
这是代码。
math.randomseed(os.time())
value = {"a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
1, 2, 3, 4, 5, 6, 7, 8, 9}
function makepassword(v)
for i = 1, v do
local v = math.random(1, 35)
local ud = math.random(0, 1)
if ud == 1 then
local p = string.upper(value[v])
else
local p = value[v]
end
if(not a) then
a = p
else
a = a..p
end
return a
end
start = makepassword(18)
print(start)
请帮助我。
存在未闭合的for
运算符,这就是它不起作用的原因。但仅仅关闭它是不够的。以下是进一步调整代码的一些方法:
math.randomseed(os.time())
-- a little more compact way of storing character sets is strings:
local charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjklmnopqrstuvwxyz123456789"
-- store the length not to calculate it every time:
local charset_length = string.len(charset)
function makepassword(length) -- here was duplicated variable name v
local a = "" -- no reason to use global a
for i = 1, length do
local v = math.random(1, charset_length)
a = a .. charset:sub(v, v)
end
return a
end
start = makepassword(18)
print(start)
老实说,我不喜欢用这种方式编码太多字符。有 Lua 函数 string.char() 从它的代码中给你一个字符,比如 string.char(48) == "0"
、string.char(65) == "A"
等。所以如果你不故意避免特殊字符,这一切都可以简单得多:
function makepassword(length)
local a = ""
for i = 1, length do
a = a .. string.char(math.random(33, 126))
end
return a
end
print(makepassword(18))
欢迎光临:)
我正在编写代码并且我 运行 它但是没有用。它没有向我显示错误消息,所以我不知道出了什么问题。谁能解决这个问题?
这是代码。
math.randomseed(os.time())
value = {"a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
1, 2, 3, 4, 5, 6, 7, 8, 9}
function makepassword(v)
for i = 1, v do
local v = math.random(1, 35)
local ud = math.random(0, 1)
if ud == 1 then
local p = string.upper(value[v])
else
local p = value[v]
end
if(not a) then
a = p
else
a = a..p
end
return a
end
start = makepassword(18)
print(start)
请帮助我。
存在未闭合的for
运算符,这就是它不起作用的原因。但仅仅关闭它是不够的。以下是进一步调整代码的一些方法:
math.randomseed(os.time())
-- a little more compact way of storing character sets is strings:
local charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjklmnopqrstuvwxyz123456789"
-- store the length not to calculate it every time:
local charset_length = string.len(charset)
function makepassword(length) -- here was duplicated variable name v
local a = "" -- no reason to use global a
for i = 1, length do
local v = math.random(1, charset_length)
a = a .. charset:sub(v, v)
end
return a
end
start = makepassword(18)
print(start)
老实说,我不喜欢用这种方式编码太多字符。有 Lua 函数 string.char() 从它的代码中给你一个字符,比如 string.char(48) == "0"
、string.char(65) == "A"
等。所以如果你不故意避免特殊字符,这一切都可以简单得多:
function makepassword(length)
local a = ""
for i = 1, length do
a = a .. string.char(math.random(33, 126))
end
return a
end
print(makepassword(18))
欢迎光临:)