Moved $random so the variable is accessible when it is being called
Removed reference to non-existent variable