Python - random module - generate random numbers from 2 options -
this python file:
import random class man: def __init__(self): self.list_of_men = [] self.createbody() def createbody: xcoord = -1 while xcoord < 16: ycoord = 0 xcoord += 1 while ycoord < 17: self.list_of_men.append(body(xcoord, ycoord, val, self)) class body: def __init__(self, menx, meny, value, man_obj): self.man_obj = man_obj self.menx = xcoord self.meny = ycoord self.value = val
actually, appending xcoord , ycoord list , want append value either 0 or 3. loop goes through 289 times , out of 289 times, there has randomly generated number 0 or 3 appended list (3 can appended 35 times).
*note: self appended man_obj in next class can use functions of first class second class.
since we're dealing small quantities, initialize list of 289 elements of 0, , randomly disperse 3's inside. can pop off list. solution wouldn't scale well, might meet specific need.
import random def foo(): = [0] * 289 = 0 while < 35: index = random.randint(0, 288) if a[index] == 0: a[index] = 3 += 1 while a: yield a.pop()
is homework assignment or similar? there more specific larger problem you're trying solve? seems unusual requirement.
Comments
Post a Comment