On receiving the randomness result, the consumer contract can use the RandcastSDK library to process the randomness result further. The library provides functions to convert the randomness result to different types that can be used in a DApp or Web3 game.
We introduce five utility functions in RandcastSDK.sol :
shuffle: This function generates a shuffled array of uniformly distributed numbers within a specified range. You can use this method for randomizing the ordering of a sequence of numbers. Examples of such usage might include shuffling cards, generating lottery numbers, etc.
draw: This function returns a subset of randomly chosen elements from an array. You can use this function for selecting one or more elements from an existing array with equal possibility. It can be used for drawing a lottery, drawing cards, selecting airdrop winners, etc.
roll: This function performs a simple random roll to pick a number within a specified size. You can use this function for selecting a number with equal possibility in a given range. For example, rolling a dice, determining the outcome of a game, randomly generating game character attributes, etc.
pickByWeights: This function chooses an index based on the given weights. It can be used when the outcome is probability-based. For example, drawing cards, minting NFTs with different rarity, or picking winners in a lottery.
batch: This function generates a batch of random numbers based on a given seed. You can choose this function for generating a set of random values through a single request. For example, generating a set of lottery tickets, verification codes, etc.