I'm trying to print a custom amount of random choices in one line looping a "print(random.choice(list)", but the problem comes when looping it with a "for" loop or something similar won't print the choices in the same line, and if I try multiplying "print(random.choice(list)" by an amount of times (or doing something similar) would print that amount of times the same random choice.
these are the options I've tried
list = ("a"), ("b"), ("c"), ("d"), ("e"), ("f"), ("g"), ("h"), ("i"), ("j")
print(random.choice(list) * 10)
that would output something like this: aaaaaaaaaa, bbbbbbbbbb, cccccccccc...
the only way to output some random choices in one line that I've found out is this:
print(random.choice(list), random.choice(list), random.choice(list), random.choice(list), random.choice(list))
that would output something like this: i d f i d
and beside that not being pretty and poorly coded, that's the output I'm looking for
You can use
random.choices()
withk=10
parameter to get 10 characters from the population (list/string) with replacement:Prints for example: