Page 1 of 1

Radom position for surf unit initaite

Posted: Mon Jan 10, 2022 2:54 pm
by Parel803
Good evening,
I'm trying to do some with random. Small steps.
I got something from another thread, thx.
I made somthing and the random position is the same for both units, no doubt logical.

Is there a way to give both a different position?

local Side = 'Civilian'
local EnvType = 'ship'
local Spd = math.random(1,10)
local Hdg = math.random(1,360,3)

local lat_var = math.random(1,(10^13))
local lon_var = math.random(1,(10^13))
v_lat = math.random(-6,8) + (lat_var/(10^13))
v_lon = math.random(90,125) + (lon_var/(10^13))

ScenEdit_AddUnit({side=Side, type=EnvType, name='test1', DBID=2355, speed=Spd, heading=Hdg, latitude=v_lat, longitude=v_lon})
ScenEdit_AddUnit({side=Side, type=EnvType, name='test2', DBID=1787, speed=Spd, heading=Hdg, latitude=v_lat, longitude=v_lon})

local u1 = ScenEdit_GetUnit({side='Civilian', name='test1'})
print (u1.latitude)
print (u1.longitude)

best regards GJ

RE: Radom position for surf unit initaite

Posted: Mon Jan 10, 2022 9:11 pm
by LettuceTurnipTheBeet
I think you need to seed your rng before calling math.random, with os.time for example, like this:

math.randomseed(os.time())

RE: Radom position for surf unit initaite

Posted: Tue Jan 11, 2022 6:53 am
by Parel803
Lettuce, thank you. Gonna try it.
regards GJ