math.randomseed(os.time())
local luck = {
{name = "凶", txt = "しばらく気をつけて過ごして!", weight = 1},
{name = "大吉", txt = "すごくいいことがあるかも!", weight = 2},
{name = "中吉", txt = "いいことも悪いこともないかな", weight = 3},
{name = "小吉", txt = "まぁまぁかも", weight = 5},
{name = "吉", txt = "普通だね", weight = 10}
}
local function roll()
local total_chance = 0
for _, item in ipairs(luck) do
total_chance = total_chance + item.weight
end
local chance = math.random(1, total_chance)
for _, item in ipairs(luck) do
if chance <= item.weight then
return item.name .. " " .. item.txt
end
chance = chance - item.weight
end
end
print("---おみくじ結果---")
print(roll())
To embed this project on your website, copy the following code and paste it into your website's HTML: