Randomizing Locations

How do you randomize an object’s location between only 2 specific points? For example, say the points are 40 and 80. When using the math.random location, it will randomize a location in the distance  between the 2 points so it would come out 43, 79, 55, etc. I want the object’s location to be randomized such that it will only be on either point, so it would come out either 40 or 80. Is there any function for that? It would be awesome if someone could tell me how to do it. Thanks.

you could this

loc = { { loc1x,loc1y},{loc2x,loc2y}}   pick = math.random(1,2) x = loc[pick][1] y = loc[pick][2]
int = math.random(1,2) if int == 1 then myPoint = 40 else myPoint = 80 end print(myPoint)
point = math.random(1,2) == 1 and 40 or 80 print(point)

Oh, I see! Using a table and if statement like that never occurred to me. Thank you so much for your help!

you could also do this

point = math.random(1,2) == 1 and {x1,y1} or {x2,y2} print(point[1],point[2])

Sorry, I have another question. How would you do this among multiple locations? Since the math.random function only accepts 2 arguments, how can you randomize it among many points?

  loc = { { loc1x,loc1y},{loc2x,loc2y},{loc3x,loc3y},{loc4x,loc4y}}   pick = math.random(1,#loc) x = loc[pick][1] y = loc[pick][2]

would be the best way

by using #loc you can add as many to the table and not have to change any other code to get x,y from table

Oh, I see. I found a solution of my own by adding multiple tables and randomizing among the randoms. But your code is much more efficient than mine, so I might use that instead.

Thank you so much for your help!

you could this

loc = { { loc1x,loc1y},{loc2x,loc2y}}   pick = math.random(1,2) x = loc[pick][1] y = loc[pick][2]
int = math.random(1,2) if int == 1 then myPoint = 40 else myPoint = 80 end print(myPoint)
point = math.random(1,2) == 1 and 40 or 80 print(point)

Oh, I see! Using a table and if statement like that never occurred to me. Thank you so much for your help!

you could also do this

point = math.random(1,2) == 1 and {x1,y1} or {x2,y2} print(point[1],point[2])

Sorry, I have another question. How would you do this among multiple locations? Since the math.random function only accepts 2 arguments, how can you randomize it among many points?

  loc = { { loc1x,loc1y},{loc2x,loc2y},{loc3x,loc3y},{loc4x,loc4y}}   pick = math.random(1,#loc) x = loc[pick][1] y = loc[pick][2]

would be the best way

by using #loc you can add as many to the table and not have to change any other code to get x,y from table

Oh, I see. I found a solution of my own by adding multiple tables and randomizing among the randoms. But your code is much more efficient than mine, so I might use that instead.

Thank you so much for your help!