Add a null check to weightedRandom input