I am attempting to create a randomly generated "perks assignment" from MMO games or games of the like.
The rules are as follows:
- Has to have 5 in one container and can only have 1 container with 5
- All 20 points have to be distributed
- Points have to be distributed by RNG (using random)
So far, all we have is this:
import random
# Variables
cont = [0, 0, 0, 0, 0]
items = 20
maxNum = 5
# Start our first loop
i = 0
while items != 0:
i = 0
while i < len(cont) - 1:
num1 = random.randint(3, maxNum)
if items < 5:
if cont[i] = 00:
cont[i] += items
items = 0
break
cont[i] = num1
if cont[i] == 5:
maxNum = 4
i += 1
items = items - num1
print(items)
print(cont)
This ends up working sometimes, but other times it will get stuck in the loop and will not work.
The way this code can be correct is that every time it outputs, it will print:
- [5,4,4,4,3]
- [4,4,4,4,4]
- [5,4,3,4,4]
- etc.
Please help me solve why it gets stuck in the loop sometimes! Thank you!