The PickRarityExample contract, by extending GeneralRandcastConsumerBase and calling functions from RandcastSDK, demonstrates a system for drawing a rarity level.
This contract also has three important parts: the constructor function, getRarity function, and _fulfillRandomWords function.
In the constructor , the rarityValue is being initialized with five string elements. These values correspond to the rarity levels of certain items or characters: 'SSSR,' 'SSR,' 'SR,' 'R,' and 'C,' each with an index from 0 to 4. The rarityWeights array is initialized with five integer elements representing the weights associated with the rarity levels defined earlier.
The function getRarity is used to request a random number.
_fulfillRandomness calls the RandcastSDK.pickByWeights function which returns an index based on a predefined rarityWeights to determine the rarity of the card drawn in this round. The lower weight corresponds to a lower probability and, therefore, a higher rarity. In this example, 'SSR' is the rarest, with the lowest probability(weight), while 'C' is the most common, with the highest probability(weight).