擅长:python、mysql、java
<p>您正在寻找<a href="https://docs.python.org/3/library/random.html#random.sample" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>from random import sample
names = ('Benjamin', 'Damien', 'Dexter', 'Jack', 'lucas', 'Norman', 'Thorn', 'Bella', 'Blair',
'Ivy', 'Lilth', 'Megan', 'Rue', 'Sabrina', 'Samara',
'Anthea', 'Jessica', 'Igor', 'Luther', 'Boris', 'Abel')
print(sample(names, k=4))
# ['lucas', 'Ivy', 'Dexter', 'Abel']
</code></pre>
<p>其中<code>k</code>参数是要选择的元素数。在</p>
<p><a href="https://docs.python.org/3/library/random.html#random.choice" rel="nofollow noreferrer">^{<cd3>}</a>将始终只选择一个元素。在</p>