random - 表值返回零?

标签 random lua

我正在制作一个随机词生成器,但遇到了一个小问题。我正在尝试从包含 closedLetters(c、d、f 等)的表中打印值,但它不起作用。它返回零。帮忙?

local closedLetters={b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, z}
local openLetters={a, e, i, o, u, y}
print(closedLetters[2])

(那段代码只是一个例子,我设置的其实更像这样)

local closedLetters={b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v, w, x, z}
local openLetters={a, e, i, o, u, y}
print(closedLetters[math.random(#closedLetters)]..openLetters[math.random(#openLetters)])

最佳答案

你在那个表中只有一堆键。具有 nil 值的键,因此您的返回值。 将它们改为文字: closedLetters= {'a', 'b', .....}

关于random - 表值返回零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17516614/

相关文章:

python - 来自 PyMC 的 FloatingPointError 从 Dirichlet 分布中抽样

javascript - 如何从 JavaScript 中的 ASCII 字符生成随机字符串

SQLite - 使用随机唯一值更新

lua - 推送可执行函数指针?

c - Lua 在 PPC Micro 上的足迹

lua - lua返回参数

lua - 逐字符读取文件到数组

c# - 尝试使基本骰子程序运行时出错

python - 如何生成不同的随机数?

lua - 如何将 ISO 8601 持续时间转换为 Lua 中的格式化字符串?