How do spawners work going in and out of the radius?

This is somewhat of an extension on this question. It has been answered that the spawner is activated when a player is withing a 17 block radius.

Suppose I'm 16 blocks from the spawner. Timer is set to randInt(200,799) meaning a Random number between 200 and 799. Let's say 444 was picked. I move to 18 blocks from spawn. Will creature still spawn after the 444 counter?

I move back in to the 16 block radius. Was the Timer reset to a new randInt(200,799), so 444 is no longer the time limit?


Solution 1:

After initializing the timer, it decreases only if a player is in range. Once the timer reaches zero, the game tries to spawn the configured entities (usually mobs). The timer is paused if all players leave the activation radius of the spawner and is resumed if the spawner is activated again. The timer is reset (re-initialized with a new random number) only after a successful spawning. If spawning conditions are not met (e.g. because the spawner area is well lit), the timer will pause at zero. Then the spawner will try to spawn entities each game tick until it succeeds (e.g. if a critical torch is removed, mobs spawn instantly).

Here is the relevant algorithm (executed each game tick):

if there are players in the activation range then
    if spawnTimeCounter > 0 then
        decrease spawnTimeCounter 
    else if spawnTimeCounter = 0 
        try to spawn entities
        if spawned at least one entity then
            initialize spawnTimeCounter with a new random value
        else if nothing spawned - do nothing
else if no player in the activation range - do nothing

source: MCP 7.5.1 MobSpawnerBaseLogic.java, Minecraft 1.5.2.