# Codey's Counting Conundrum

When I was investigating the project, I found Math.floor(Math.random() * 5) * 90 + 25
and I understand the Math.floor(Math.random().
But why * 5) * 90 + 25?

what do these numbers indicate?

Thanks

``````
// Helper function to return an object containing evenly spaced x and y coordinates:
generateRandomCoords () {
const randomX = Math.floor(Math.random() * 5) * 90 + 25
const randomY = Math.floor(Math.random() * 5) * 100 + 25
return { x: randomX, y: randomY }
}

// Helper function that returns one set of coordinates not in gameState.numCoordinates
assignCoords () {
let assignedCoord = this.generateRandomCoords();

// If the coordinates is already in gameState.numCoordinates, then other set of coordinates are generated until there is one not in use
while (gameState.numCoordinates[`x\${assignedCoord.x}y\${assignedCoord.y}`]) {
assignedCoord = this.generateRandomCoords()
}

gameState.numCoordinates[`x\${assignedCoord.x}y\${assignedCoord.y}`] = true

return assignedCoord
}
}
``````

It’s in steps. We floor *5 first, that gives us an integer {0,…,4]. The maximum for X is 385, a fixed number given the initial 4. The maximum for Y is 425. If you work backwards you’ll see only four other steps for each. And they are all fixed numbers.

so the Width is 385

0* 90 = 0
1* 90 = 90
2* 90 = 180
3* 90 = 270
4* 90 = 360

25 is the margin of the bg, so the 5 rows move to right together for 25

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.