Hey there!

So I assume what you're asking for is to be able to have a target number and then to come up with a bunch of random numbers (within a range) that add up to the target number.

Though I don't have all the details, the way I would approach this is as follows:

1) Take your target number (round difficulty) and divide it by the max difficulty an enemy can have (assuming the lowest difficulty an enemy can have is 0) divided by two. In other words:

```
var number_of_enemies = target_difficulty / (max_enemy_difficulty * 0.5)
```

This will give you how many enemies there will be in a round. Unfortunately, the desired answer is a function of the possible range of difficulty of an enemy, the target difficulty of the round, and the number of enemies. This is assuming that the number of enemies won't be exactly defined but rather determined by the input desired difficulty and the possible range of the enemy difficulty. If you want a specific number of enemies in your round guaranteed, simply take your max enemy difficulty, divide it by two, and then multiply that by how many enemies you want in the round and use that as your target difficulty.

2) Populate an array of number*of*enemies length with max*enemy*difficult * 0.5:

```
var all_enemies = []
for i in range(number_of_enemies):
all_enemies.append(max_enemy_difficulty * 0.5)
```

This will be the array containing all the individual difficulties of all the enemies in the round. Right now, they'll all be set to half what they could be at the max. This is intended.

3) Here comes the magic -- pick two random indexes within the all_enemies array, increase one of them by one, and subtract one from the other one. That way, the sum of all the enemy difficulties stays the same no matter how many times you change it, but the actual individual enemies' difficulties get randomized.

```
var rand = RandomNumberGenerator.new()
rand.randomize()
for i in range(number_of_changes):
# picking an index in the array, and then if it is at the max enemy difficulty, picking a different one (because this index will only be added to, and if its at the max you cant add anything)
var ind_1 = rand.randi_range(0, all_enemies.size() - 1)
while all_enemies[ind_1] >= max_enemy_difficulty:
ind_1 = rand.randi_range(0, all_enemies.size() - 1)
#same as before, but checking if the second index is at the minimum it can be (because this index will be subtracted from)
var ind_2 = rand.randi_range(0, all_enemies.size() - 1)
while all_enemies[ind_2] <= 0:
ind_2 = rand.randi_range(0, all_enemies.size() - 1)
all_enemies[ind_1] += 1
all_enemies[ind_2] -= 1
```

this should be the end of it. As you can see, this code takes in the target difficulty/total round difficulty (which I set to 10 in this example), max difficulty of an enemy (which I set to 4) and the min difficulty (but that's assumed to be 0) and outputs an array with every individual enemy's difficulty:

Hope this helped, and if I misunderstood the question or you need some further guidance or variables to be tweaked, don't hesitate to let me know.

(Just for clarity, here's what the final code that I used to generate that example looks like):