AMARANT Posted August 10, 2012 Posted August 10, 2012 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.
Lloyd Logan Posted August 11, 2012 Posted August 11, 2012 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?
Dev Posted August 12, 2012 Posted August 12, 2012 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 = { [1] = { a, b, c } [2] = { d, e, f } [3] = { g, h, i } [4] = { 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now