The attention method is used. there is an explanation on the internet. Simply put, a string of numbers is randomly generated, and then a subscript is used to determine whether these numbers are repeated. if they are repeated, a screening is performed.
The code is as follows:
Import random
Print 'n' must> K else error'
N = int (raw_input ("n = "))
K = int (raw_input ("k = "))
Result = []
X = range (n)
For I in range (k ):
T = random. randint (I, n-1)
Temp = x [I]
X [I] = x [t]
X [t] = temp
Result. append (x [I])
Print result
Raw_input ('inpuy AnyKey to exit ')
This is generated using algorithms. actually, python has a method.
Random. sample (list, n) is to randomly select n different elements from the list.
The code is as follows:
Import random
For I in range (4 ):
Print random. sample (['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'], 7)