Page 1 of 1

[Resolved] Random Question

Posted: Tue Jun 18, 2019 7:12 pm
by TheSAguy
Why is my code below creating a line vs. random.
I'd expect the x and y values to be random and thus the chart to be all over the place.

Code: Select all

			local radius = 2.5
			local x_offset = math.random(-250, 250) 
			local y_offset = math.random(-250, 250) 
			local position = {x_offset, y_offset}
			local area = {{x_offset - radius, x_offset - radius}, {x_offset + radius, x_offset + radius}}			

		
			for _,force in pairs( game.forces )do
				force.chart( game.surfaces[1], area)		
			end
Image

Re: Random Question

Posted: Tue Jun 18, 2019 7:17 pm
by steinio
because math.random with values smaller then 317 results in the same value: viewtopic.php?t=19353#p123786

Re: Random Question

Posted: Tue Jun 18, 2019 7:24 pm
by eduran

Code: Select all

local area = {{x_offset - radius, x_offset - radius}, {x_offset + radius, x_offset + radius}}
You are using x_offset twice and y_offset not at all.
steinio wrote:
Tue Jun 18, 2019 7:17 pm
because math.random with values smaller then 317 results in the same value: viewtopic.php?t=19353#p123786
That is not true. It produces deterministic pseudo-random numbers.

Re: Random Question

Posted: Tue Jun 18, 2019 7:37 pm
by TheSAguy
eduran wrote:
Tue Jun 18, 2019 7:24 pm

Code: Select all

local area = {{x_offset - radius, x_offset - radius}, {x_offset + radius, x_offset + radius}}
You are using x_offset twice and y_offset not at all.

face-palm!

Thanks,.

Re: Random Question

Posted: Tue Jun 18, 2019 7:41 pm
by eradicator
The whole "seeds below x produce same random output" is a problem with LuaRandomGenerator, not math.random anyway. And even then only if you run *multiple generators in parrallel*. Totally not related to this.

You can't chart less than one chunk, so your very small radius will have no effect unless your position is really close to a chunk border.

Code: Select all

/c
for i=1,10 do
  local r = 0.0001
  local x,y = math.random(-250,250), math.random(-250,250)
  local area = {{x-r,y-r},{x+r,y+r}}
  game.forces.player.chart(game.surfaces.nauvis,area)
  end