private void randomAssign(Map<String, Partition> partitionToAssignMap,
            List<ConsumerInfo> consumerList,
            Map<String, Map<String, List<Partition>>> clusterState,
            Map<String, Map<String, Map<String, Partition>>> oldClusterState,
            List<String> filterList) {
        int searched = 1;
        int consumerSize = consumerList.size();
        for (Partition partition : partitionToAssignMap.values()) {
            ConsumerInfo consumer = null;
            int indeId = RANDOM.nextInt(consumerSize);
            do {
                searched = 1;
                consumer = consumerList.get(indeId);
                if (filterList.contains(consumer.getConsumerId())) {
                    if (consumerList.size() == 1) {
                        searched = 0;
                        break;
                    }
                    Map<String, Map<String, Partition>> oldPartitionMap =
                            oldClusterState.get(consumer.getConsumerId());
                    if (oldPartitionMap != null) {
                        Map<String, Partition> oldPartitions =
                                oldPartitionMap.get(partition.getTopic());
                        if (oldPartitions != null) {
                            if (oldPartitions.get(partition.getPartitionKey()) != null) {
                                searched = 2;
                                indeId = (indeId + 1) % consumerSize;
                            }
                        }
                    }
                }
            } while (searched >= 2);
            if (searched == 0) {
                return;
            }
            Map<String, List<Partition>> partitions =
                    clusterState.computeIfAbsent(consumer.getConsumerId(), k -> new HashMap<>());
            List<Partition> ps = partitions.computeIfAbsent(
                    partition.getTopic(), k -> new ArrayList<>());
            ps.add(partition);
        }
    }
Random assign partition

@param partitionToAssignMap
@param consumerList
@param clusterState
@param oldClusterState
@param filterList
inlong-tubemq/tubemq-server/src/main/java/org/apache/inlong/tubemq/server/master/balance/DefaultLoadBalancer.java