Math.random (Interval is empty) ERROR

I’m trying to make a simple space shooter for learning the game engine.
I want to enemy spawn diffirent position on the scene but using math with screen dimension, it doesnt work.

local enemy_spawn_rate = 60 -- per minute

function init(self)
	local pos = go.get_position()
	local window_x, window_y = window.get_size()

	pos.x = window_x / 2
	pos.y = window_y - 20

	go.set_position(pos)

	print(window_x)
	
	timer.delay(enemy_spawn_rate / 60, true, function()
		factory.create("#factory")

		pos.x = math.random(window_x, 0)

		go.set_position(pos)
	end)
end

ERROR:SCRIPT: main/enemy_spawner.script:17: bad argument #2 to 'random' (interval is empty) stack traceback: [C]:-1: in function random main/enemy_spawner.script:17: in function <main/enemy_spawner.script:14>

According to API reference (math) if you pass two arguments to math.random they should be two integers m, n with m less than or equal to n.

I am not sure what you want to implement here. Probably something like

pos.x = window_x * math.random()

?

This set pos.x to a random position in the range [0, window_x]. You could also use math.random(0, window_x) but I am not sure if this would still work if window_x is not an integer.

Yeah this is exacly what i want but, i missed the m less than or equal to n. part and put number wrong order.

Thank you!