def random_partition(self):
        state = self.state_factory.load()
        containers = [c.name for c in self._get_running_containers(state=state)
                      if not c.holy]

        # no containers to partition
        if not containers:
            return []

        num_containers = len(containers)
        num_partitions = random.randint(1, num_containers)

        # no partition at all -> join
        if num_partitions <= 1:
            self.join()
            return []
        else:
            pick = lambda: containers.pop(random.randint(0, len(containers)-1))

            # pick at least one container for each partition
            partitions = [[pick()] for _ in xrange(num_partitions)]

            # distribute the rest of the containers among the partitions
            for _ in xrange(len(containers)):
                random_partition = random.randint(0, num_partitions-1)
                partitions[random_partition].append(pick())

            self.partition(partitions, state)
            return partitions
dataset/ETHPy150Open dcm-oss/blockade/blockade/core.py/Blockade.random_partition/original