I'm having this problem in python where I can't generate different random numbers in a loop. Every loop generates same numbers. My code looks like this:
import random
class Dna :
genes = []
lifespan = 0
def __init__(self, lifespan) :
self.lifespan = lifespan
sum = 0
for i in range(lifespan) :
self.genes.append(PVector(random.randrange(-10, 10), random.randrange(-10, 10)))
sum += self.genes[i].mag()
print(sum)
Here, I'm trying to generate random vectors in the range -10 and 10 but every different DNA object prints the same sum. Here is the main file:
import dna
def setup() :
size(600, 600)
d = dna.Dna(200)
d2 = dna.Dna(200)
And I'm using processing.py for this.
Aucun commentaire:
Enregistrer un commentaire