randomly spawn more objects ?

hi, in my game i want to spawn ships at random intervals up to a maximum amount. i started the script off but got stuck along the way if you could please help.

i have commented the parts that i need to do and given a short description of what to do. First, make the script wait for a random number of seconds using the min and max auto spawn times. Secondly, complete the if statement by finding the number of ships that are a child of the ShipController and whether there are less than the maximum ships allowed. If the number of ships is less than the maximum allowed then the script will spawn another ship, else it will stop autospawning by setting ‘autoSpawn’ to false, ending the while statement.

var maxShips:int = 4;
	 
	// min and max time between automatically spawning ships
	var minAutoSpawnTime:int = 10;
	var maxAutoSpawnTime:int = 30;

function StartAutomaticSpawn()
	{
	    // autospawn toggle
	    var autoSpawn:boolean = true;
	     
	    // while allowed to autospawn
	    while (autoSpawn)
	    {
	                    // wait for a random X seconds (between min  max)   //NEED HELP
	         
	         
	        // if there are currently less ships than the max allowed
	        if ( )                          //NEED HELP
	        {
	            // spawn another ship
	            SpawnShip();
	        }
	        else // otherwise stop autospawning
	        {
	            autoSpawn = false;
	        }
	    }
	}

First and formost… I’m sorry if any code is wrong… it’ll be close or correct, but I am on my droid
And typimg isn’t the greatest on here… I also use c# so it may be slightly off, but I tried to write it in js…
Anyway here goes

var x: int = random.range(minAutoSpawnTime, maxAutoSpawnTime);

yield waitForSeconds(x);

// I would make an array of enemy ships then use arrayName.length
// to get the number of spawned enemies...remember to add enemies to
// the array when creating them... I would use a list in c# with the add function, but
// I'm unsure of the js equivilant so guess this is all I got for now