Fiel Wrote:Code:
import random
possibleNumbers = range(1, 50)
random.shuffle(possibleNumbers)
randomNumbers = [str(number) for number in possibleNumbers[0:6]]
print(', '.join(randomNumbers))
possibleNumbers is, if I'm not mistaken, an array holding values from 1 to 50.
random.shuffle is a method from the random class (I can't speak with too much confidence here since I have little idea how Python is structured internally). Basically it takes an array and randomly swaps different values to different indices. e.g: [1,2,3,4,5] -> [3,2,5,4,1]
This process is done in-place, meaning it performs the operation on the array you give it and not produce anything new. It's like cooking a corn, if you will.
str(number) serves to type-cast the number into a string format, so it follows that randomNumbers is a list of strings. (e.g: randomNumbers = ["12","15","6","7",...])
The whole line translates into English as: Take the first 6 values in the possibleNumbers array (which was shuffled randomly), convert each of them into a string and store them in their respective index of the list randomNumbers.
Then you just print that list.