我正在尝试制造一种提供随机伤害的武器。我这样做是使用表单中的项目数据库
itemsList = {
1: {"name": "Padded Armor", "armor": 1, "value": 5, "class": "Light"},
2: {"name": "Leather Armor", "armor": 2, "value": 10, "class": "Light"},
....
19: {"name": "Dagger", "damage" : int(random.randrange(1, 4)), "value": 2, "Type": "Dagger"},
20: {"name": "Dagger + 1", "damage" : int(random.randrange(1, 4) + 1), "value": 200, "Type": "Dagger"},
21: {"name": "Dagger + 2", "damage" : int(random.randrange(1, 4) + 2), "value": 750, "Type": "Dagger"},
22: {"name": "Dagger + 3", "damage" : int(random.randrange(1, 4) + 3), "value": 2000, "Type": "Dagger"}
}
每次我尝试调用"damage"
它时都会返回相同的结果。我知道这是因为随机数生成一个然后保存到该字典键。
每次调用损坏时,我将如何生成一个随机数?