rarity algorithm