random
solution
If you want to only use the random
module, you can use:
import random
nums = random.sample(range(1,35), 10)
winning_numbers = nums[:7]
bonus_numbers = nums[7:]
>>> winning_numbers
[2, 23, 29, 34, 26, 16, 13]
>>> bonus_numbers
[8, 4, 19]
As random.sample
is "Used for random sampling without replacement." (Quoted from the docs)
numpy
solution
You can also use numpy
, as numpy.random.choice
has a replace
argument you can set to false
. (I'm personally a fan or using numpy
for random numbers, as it provides a lot more flexibility in more complex tasks than random
)
import numpy as np
nums = np.random.choice(range(1,35), 10, replace=False)
winning_numbers = nums[:7]
bonus_numbers = nums[7:]
>>> winning_numbers
array([27, 4, 17, 30, 32, 21, 23])
>>> bonus_numbers
array([15, 13, 18])