The only way to generate 50 lists of random numbers (short of writing out all those commands sequentially) is to go through 50 loops generating the numbers. The standard way to do this in most programming languages is with nested loops. Some languages have features, or available libraries that can make this easier to write and/or more effecient. Python has a feature called list comprehension
s that make creating lists very easy and convenient.
import random
[random.randint(0,1) for _ in range(10)]
They can also be nested to accomplish your task.
import random
[[random.randint(0,1) for _ in range(x)] for x in range(10,501,10)]
Timing:
from random import randint
from timeit import timeit
def lc():
return [[randint(0,1) for _ in range(x)] for x in range(10,501,10)]
def forloop():
outer = []
for x in range(10,501,10):
inner=[]
for _ in range(x):
inner.append(randint(0,1))
outer.append(inner)
return outer
print(timeit(lc,number=100)) # 9.2758308192958
print(timeit(forloop,number=100)) # 9.44730854274725
Hmmm. I was under the impression that list comps had more of a speed advantage over for loops.