jeudi 16 décembre 2021

How to generate random pattern of data with specific probability?

I don't know how to change my code to generate a random pattern of alive cells. numpy is not allowed. (CellType(True) = "O"

def seed_random(self, confluency, CellType=Cell):
    self.confluency = float(confluency)
    
    x = random.uniform(0,1)
    print(x)
    cu_prob = 0.0
    test_matrix = list()
    for i in range(self.rows):
        test_matrix.append([])
        for j in range(self.cols):
            test_matrix[i].append(CellType(False))
            cu_prob += confluency
            if x < confluency:
        
                test_matrix[i][j]=CellType(True)
            else:
                test_matrix[i][j]=CellType(False)

    self.matrix = test_matrix

I want my output look like this when confluency is 0.5.

O..OOO..OO.O.OO.O..OO..OOOOOOOOOOOOO...O

..OO...O..O.....OO.OO...OO...OOOO...OO..

...O...OO..O.......OO..O.OOO...OOOO.....

O..OOO.OO.OOO.OO.OOOOOOOO..O..OOO.O...O.

..O.O.O.OO..O.O..OOO.O...O....OOO.OOO.OO

O..OOO..OO...O..O.O.OO.O...OOO....O.OOO.

..O..O.OOO...OO..O.OO.OO.OOOO.O.O..OOOO.

OO.O.OOO...OO.....O.OOOO.O...OOOO..OO...

OOOO.OO.O.O.O..O.O...OO..O.O.OO......OOO

..OO.....OOOOO.O.OOOOO.OO.OO...O..OOOOO.

but my output is either this or circles

........................................

........................................

........................................

........................................

........................................

........................................

........................................

........................................

........................................

........................................




Aucun commentaire:

Enregistrer un commentaire