add condition for calling sample on an empty array