jeudi 5 juillet 2018

Percent of time that number will spawn

So I have a program to spawn numbers in 2048. Right now the chances of a 2 or 4 spawning are 50/50.

nlist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
def spawnnum():
    x = []
    for i in range(0, 16):
        if nlist[i] == 0:
            x.append(nlist[i])
    y = random.randint(1, len(x))
    count = 0
    for j in range(len(nlist)):
        if nlist[j] == 0:
            count += 1
        if count == y:
            nlist[j] = 2 * random.randint(1, 2)
            break

Is there a way of making the program so that the chances of a 4 spawning is 10% of the time and a 2 spawning is 90% of the time. BTW the place where this program actually spawns the number is nlist[j] = 2 * random.randint(1, 2)(Second to last line).




Aucun commentaire:

Enregistrer un commentaire