Find a suitable spawning position for an entity

Hey everyone. I was wondering if is a way to spawn an entity in a random location without it spawning in a wall or in the air?
Here’s my spawning code so far:


local function SpawnBuks()
local x = math.random(-13000, 13000)
local y = math.random(-13000, 13000)
local z = math.random(-11000, 513)
local ent = ents.Create( "bluebuk" )
if ( !IsValid( ent ) ) then return end // Check whether we successfully made an entity, if not - bail
ent:SetPos( Vector( x, y, 513 ) )
ent:Spawn()
ent:Activate()
local phys = ent:GetPhysicsObject()
if ( IsValid( phys ) ) then
	phys:EnableMotion(true)
	phys:Wake()
	end
end

Any help is appreciated :v:

navmesh.GetAllNavAreas
Requires navmesh for the map (mapname.nav)
table.Random + GetPos. That would be simple one, you could also make checks that its accessible and not underwater etc.

Thanks!