'Is there a way to split an infinite or a number of choosing into 3 or more randomized sizes for a population type of code?

I'm trying to figure out how to add onto my code where it randomly splits the number of my choosing into a number of my choosing size. For example, I want to have 3 cities where my randomized humans are put into, and I can choose how many I create, let's say

amount_of_humans_to_make = 98327

And these humans are put into a list "li[]" And I want to randomly put them into a chosen amount of cities, for simple sake "3". And it has to be random sizes without duplicates, I don't want it to be hard coded, I want to be able to have the freedom of changing the numbers to what ever I want. This is the code I use right now for the cities

def make_cities(populations):
  City_Name = ["NewYork", "Alabama", "Boston"]
  res = [
    make_city(populations[0:30], City_Name[0]),
    make_city(populations[31:60], City_Name[1]),
    make_city(populations[61:90], City_Name[2])
    ]
  return res

If anyone could help would be much appreciated.



Solution 1:[1]

I would solve it in a simple way. For each person I would basically call random.randint(0,3) and assign that person to that city. In this way you will easily achieve the thing you want to do and it would be much more logical since this is kind of the thing we do in Randomized Control Trials.

for p in population:
    city_selected = random.randint(0,3)
    # Associate City_Name[city_selected] with p

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2736738