Using a grid and placing objects


I am trying to place objects randomly within the boxes with a grid.
I am using this method to draw the grid:


void ofDrawGrid(float stepSize=1.25f, size_t numberOfSteps, bool labels=false, bool x=true, bool y=true, bool z=true)

I know you can generate random numbers between certain limits. What I am trying to work out is how I can use the stepSize and number of steps in the grid method to calculate generate random x and y coordinates for my object to ensure it is in the grid boxes


I would start trying to build a loop first, that draws rows and columns first. Are you working in 3D or 2D?

int xPadding = 100;
int yPadding = 100;

for(int x = 0; x < ofGetWidth(); i+=xPadding){
    for(int y = 0; y < ofGetHeight(); i+=yPadding){
        ofLog() << "cell coordinates";
        ofLog() << x;
        ofLog() << y;
        // how x and y change in the loop? how can you use them to draw your objects?


I am working in. 3d


you could use the same loop as before with ofDrawSphere.