Workshop › Conway's Game of Life › Step 7 of 32
To start, about a quarter of the cells come alive at random. map makes a new grid from the old one, cell by cell.
```js
function randomize() {
grid = grid.map((row) => row.map(() => (Math.random() < 0.25 ? 1 : 0)))
}
function reset() {
grid = emptyGrid()
randomize()
}
```Math.random() gives a random number from 0 up to 1; < 0.25 is true about one time in four.condition ? 1 : 0 is 1 when the condition is true, 0 otherwise.grid.map(...) makes a new list with one result for each row; the inner row.map(...) does the same for each cell.reset now makes an empty grid and fills it at random.randomize above function reset() {, with an empty line between them.reset, under grid = emptyGrid(), call randomize(). Press Run.Skills: Arrays and objects
← Draw every living cell Count the neighbours →