ARPA Network
  • ARPA Network
  • Becoming a node & get rewarded
    • Native Staking
      • Introduction to Staking v0.1
    • Eigenlayer Integration
  • Randcast
    • Getting Started
      • Use Web GUI
        • Subscription Management Portal
        • Remix
      • Use Randcast CLI
      • Use Solidity Development Tools
    • Using the SDK
      • Adapter
      • BasicRandcastConsumerBase
      • GeneralRandcastConsumerBase
      • Randcast Utilities
      • Consumer Contract Examples
        • Example - Get Random Number
        • Example - Roll a Dice
        • Example - Shuffle an Array
        • Example - Draw a Lottery
        • Example - Pick a Property
        • Example - Pick a Rarity
        • Example - Pick a Winner
        • Example - Advanced Request
    • Supported Networks & Parameters
  • GitHub Repositories
Powered by GitBook
On this page
  1. Randcast
  2. Using the SDK

Randcast Utilities

PreviousGeneralRandcastConsumerBaseNextConsumer Contract Examples

Last updated 10 months ago

On receiving the randomness result, the consumer contract can use the RandcastSDK library to process the randomness result further. The 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.

function shuffle(uint256 upper, uint256 randomness) pure returns (uint256[] memory)

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 cards, selecting airdrop winners, etc.

function draw(uint256 seed, uint256[] memory indices, uint256 count) pure returns (uint256[] memory)

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, , etc.

function roll(uint256 randomness, uint256 size) pure returns (uint256 number)

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 , or picking winners in a lottery.

function pickByWeights(uint256 randomness, uint256[] memory valueWeights) pure returns(uint256 chosenIndex)

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.

function batch(uint256 seed, uint256 length) pure returns (uint256[] memory)

These functions essentially cover most of the usage scenarios for random numbers. You can use them based on your needs or modify them according to your requirements.

library
drawing a lottery
randomly generating game character attributes
with different rarity