Want to choose multiple random numbers from a given list of numbers in python
<p>In Python how can I choose two or more random numbers from a given list,such that the numbers are chosen in the same sequence they are arranged in the list they are chosen from?It seems random.choice selects only one number from the list per iteration and as stated earlier random.sample does not give satisfactory answers.for example:</p>

<pre><code>import random
a=['1','2','3','4','5','6','7','8']
b=['4','3','9','2','7','1','6','5']
c=random.sample(a,4)
d=random.sample(b,4)
print "c=",c
print "d=",d
</code></pre>

<p>The code gives me the following result:</p>

<pre><code>c=['4','2','3','8']
d=['1','9','5','4']
</code></pre>

<p>But I want the answer as:</p>

<pre><code>c=['4','5','6','7']
d=['9','2','7','1']
</code></pre>

<p>or</p>

<pre><code>c=['5','6','7','8']
d=['7','1','6','5']
</code></pre>

<h3>Answer for original version of question:</h3>

<p>To get two samples randomly, use <a href="https://docs.python.org/3/library/random.html" rel="nofollow"><code>random.sample</code></a>.  First, lets define a list:</p>

<pre><code>&gt;&gt;&gt; lst = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
</code></pre>

<p>Now, lets get two samples randomly:</p>

<pre><code>&gt;&gt;&gt; random.sample(lst, 2)
[13, 16]
&gt;&gt;&gt; random.sample(lst, 2)
[10, 12]
</code></pre>

<p>Sampling is done without replacement.</p>

python python-2.7 random