How can I build a random team generator using python? I have a team of 60 and want to divide them into 10 groups.
Asked
Active
Viewed 731 times
-2
-
Take a look at the [`random.choices()`](https://docs.python.org/3/library/random.html#random.choices) function, and take it from there. – Jens Oct 30 '19 at 06:48
-
3use `random.shuffle` and slicing. – AVX-42 Oct 30 '19 at 06:48
1 Answers
1
Easiest would probably be to just shuffle and slice the original pool:
import random
pool = list(range(60)) # or some other list of length 60
random.shuffle(pool)
teams = [pool[i:i+6] for i in range(0, 60, 6)]
teams
[[28, 7, 59, 43, 2, 39],
[26, 53, 33, 3, 17, 34],
[9, 21, 58, 36, 37, 4],
[57, 38, 56, 15, 23, 1],
[10, 49, 52, 0, 40, 13],
[27, 14, 35, 47, 45, 18],
[12, 46, 6, 55, 11, 30],
[19, 22, 54, 41, 16, 20],
[50, 44, 29, 48, 8, 42],
[5, 51, 25, 31, 32, 24]]

user2390182
- 72,016
- 6
- 67
- 89