我正在尝试编写一些代码(伪随机地)生成7个数字的列表。我让它运行一次。我希望能够循环这段代码以生成多个列表,我可以将其输出到txt文件中(我不需要帮助,我很喜欢使用I / O和文件:)
我现在正在使用此代码(感谢Jason到此为止):
import random
pool = []
original_pool = list( range( 1,60))
def selectAndPrune(x):
pool = []
list1 = []
random.shuffle(pool)
pool = original_pool.copy()
current_choice = random.choice(pool)
list1.append(current_choice)
pool.remove(current_choice)
random.shuffle(pool)
print(list1)
def repeater():
for i in range(19):
pool_list = []
pool = original_pool.copy()
a = [ selectAndPrune(pool) for x in range(7)]
pool_list.append(a)
repeater()
这给出了单个值列表的输出,例如:
[21]
[1]
[54]
[48]
[4]
[32]
[15]
etc.
我想要的输出是19个列表,全部包含7个随机整数:
[1,4,17,23,45,51,3]
[10,2,9,38,1,24]
[15,42,35,54,43,28,14]
etc