# Randcast Utilities

On receiving the randomness result, the consumer contract can use the `RandcastSDK` library to process the randomness result further. The [library](https://github.com/ARPA-Network/Randcast-User-Contract/blob/main/contracts/user/RandcastSDK.sol) 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.

```solidity
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 a lottery](/randcast/using-the-sdk/consumer-contract-examples/example-draw-a-lottery.md), drawing cards, selecting airdrop winners, etc.

<pre class="language-solidity"><code class="lang-solidity"><strong>function draw(uint256 seed, uint256[] memory indices, uint256 count) pure returns (uint256[] memory)
</strong></code></pre>

**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](/randcast/using-the-sdk/consumer-contract-examples/example-pick-a-property.md), etc.

```solidity
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 [with different rarity](/randcast/using-the-sdk/consumer-contract-examples/example-pick-a-rarity.md), or picking winners in a lottery.

```solidity
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.

```solidity
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arpanetwork.io/randcast/using-the-sdk/randcast-utilities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
