What potential pitfalls should be considered when distributing points in a grid to avoid overlap in PHP?

When distributing points in a grid in PHP, one potential pitfall to consider is the possibility of overlapping points. To avoid this, you can keep track of the points that have already been placed and ensure that new points do not overlap with existing ones.

$points = [];

function distributePoints($gridSize, $numPoints) {
    global $points;
    
    for ($i = 0; $i < $numPoints; $i++) {
        $x = rand(0, $gridSize - 1);
        $y = rand(0, $gridSize - 1);
        
        $point = [$x, $y];
        
        while (in_array($point, $points)) {
            $x = rand(0, $gridSize - 1);
            $y = rand(0, $gridSize - 1);
            $point = [$x, $y];
        }
        
        $points[] = $point;
    }
}