optimize randomElements performance