Moving the random seems to prevent errors.