# Random points on the map

## Recommended Posts

Hello there How can I create 5 random coordinates from my table of 100 different ones so that they don't be repeated? I mean it might be a mess if a random coordinate turns out 17 and then it turns out 17 again.

Hello there How can I create 5 random coordinates from my table of 100 different ones so that they don't be repeated? I mean it might be a mess if a random coordinate turns out 17 and then it turns out 17 again.

math.random?

You can use this code, however the co-ordinates I have placed in 'theCoordinates' table are just imaginary, you will have to replace them with your own.

```local theCoordinates =
{
 = { a, b, c }
 = { d, e, f }
 = { g, h, i }
 = { j, k, l }
}

local lastCoordinate = nil
function getRandomCoordinate( )

local index = tonumber( math.random( 1, 4 ) )
if ( index ~= lastCoordinate ) then

lastCoordinate = index

local x, y, z = unpack( theCoordinates[ index ] )
return x, y, z
else
getRandomCoordinate( )
end
end
```

## Create an account

Register a new account