It doesn't use the whole list because the chunks are of random size. Whether or not three random chunks take up the whole list is... well, a bit random.
So you may have to respecify the problem slightly if you want it solved. Which is more important to you, random sized chunks between 1 and 3...
from random import randint
lst = [1, 2, 3, 4, 5, 6, 7, 8]
min_chunk_size=1
max_chunk_size=3
number_of_chunks=3
chunked_list = []
for _ in range(number_of_chunks):
# calculate a random chunk size
chunk_length = randint(min_chunk_size, max_chunk_size)
# copy a slice from the front of your list into your list of chunks
# you need the min(chunk_length, len(lst)) in case the chunks deplete the whole list
chunk = lst[:min(chunk_length,len(lst))]
chunked_list.append(chunk)
# then remove that slice from the original list
lst = lst[chunk_length:]
print(chunked_list)
... or using the whole list?
from random import randint
lst = [1, 2, 3, 4, 5, 6, 7, 8]
min_chunk_size=1
max_chunk_size=3
number_of_chunks=3
chunked_list = []
# create one fewer chunk than you need...
for _ in range(number_of_chunks-1):
chunk_length = randint(min_chunk_size, max_chunk_size)
chunk = lst[:min(chunk_length,len(lst))]
chunked_list.append(chunk)
lst = lst[chunk_length:]
# ... and add what's left as the last chunk, even if it's the wrong size
chunked_list.append(lst)
print(chunked_list)