function randomlevel(levelnodes,len,w)
	local level = {}
	
	len = len or 10
	w = w or len
		
	function rand (north,east,south,west,fr) 
		local all = table.keyintersection(
			north and levelnodes.north[north.south] or nil,
			south and levelnodes.south[south.north] or nil, 
			east and levelnodes.east[east.west] or nil, 
			west and levelnodes.west[west.east] or nil)
		local chs = {}
		
		for a,b in pairs(all) do 
--				_print(b.name)
			table.insert(chs,b)
		end
		local n = table.getn(chs)
		local chose = math.floor(math.random()*(n))+1
		
		if (false) then --do
			--_print(fr)
			--_print("",north and north.id,north and north.south)
			local prn = {} if (west) then for a,b in levelnodes.west[west.east] do table.insert(prn,b.id) end end
			--_print(west and west.id, chs[chose].id, east and east.id,table.concat(prn,", "))
			local prn = {} for a,b in levelnodes.north[south.north] do table.insert(prn,b.id) end
			--_print("",south and south.id,south and table.concat(prn,", "))
			local prns = {}
			for a,b in pairs(all) do prns[a] = b.id end
			--_print(table.concat(prns,", "))
		end
		return chs[chose]
	end
	
	local row = {}
	for i=1,w do row[i] = levelnodes.nodes.plain_1_1_1_1 end
	
	for i=0,len or 500 do 
		local row2 = {}
		for j=1,w do 
			row2[j] = rand(nil,nil,row[j],row2[j-1])
			if (row2[j]) then 	table.insert(level,{row2[j].name,j-w/2,i-len/2,0}) end
		end
		row = row2
	end
	return level
end