擅长:python、mysql、java
<p>您有两个基本选项,这取决于(假设您是在一个两行的情况下)是要选择两个随机行,还是选择任意两个随机行两次。也就是说,是否允许重复。在</p>
<p>如果你想允许重复,你需要先选择一个<a href="https://docs.python.org/3/library/random.html#random.randint" rel="nofollow">^{<cd1>}</a>,然后运行你已经有很多次的代码。这是“随机抽取一行,随机抽取若干次。”</p>
<pre><code># print one or two random lines: possibly the same line twice!
for i in range(random.randint(1, 2)): # change the upper bound as desired
print(random.choice(nameLines))
</code></pre>
<p>在另一种情况下,使用<a href="https://docs.python.org/3/library/random.html#random.sample" rel="nofollow">^{<cd2>}</a>,然后打印所有结果。这是“随机选取离散线数”。在</p>
^{pr2}$
<hr/>
<p>为你的用例使用合适的一个!在</p>