擅长:python、mysql、java
<p>创建<code>stats</code>列表的随机排列,然后按排列顺序分配<code>Strength</code>、<code>Dexterity</code>等。这样做还有一个额外的好处,即在创建新角色之前不需要重置列表</p>
<pre><code>from random import shuffle
# ...
stats = [8, 10, 11, 12, 14, 15]
shuffle(stats)
Strength = stats[0]
Dexterity = stats[1]
Constution = stats[2]
Intelligence = stats[3]
Wisdom = stats[4]
Charisma = stats[5]
</code></pre>
<p>作为旁注,没有必要将默认值<code>0</code>分配给<code>Strength</code>等,因为它们将在之后立即更改</p>