> For the complete documentation index, see [llms.txt](https://docs.arpanetwork.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arpanetwork.io/randcast/using-the-sdk/consumer-contract-examples/example-advanced-request.md).

# Example - Advanced Request

The `AdvancedGetShuffledArrayExample` shows how to request and consume randomness of type `Shuffling` without extending `GeneralRandcastConsumerBase`.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {BasicRandcastConsumerBase} from "randcast-user-contract/user/BasicRandcastConsumerBase.sol";
import {RequestIdBase} from "randcast-user-contract/utils/RequestIdBase.sol";
// solhint-disable-next-line no-global-import
import "randcast-user-contract/user/RandcastSDK.sol" as RandcastSDK;

contract AdvancedGetShuffledArrayExample is RequestIdBase, BasicRandcastConsumerBase, RandomnessHandler {
    mapping(bytes32 => uint256) public shuffledArrayUppers;
    uint256[][] public shuffleResults;

    // solhint-disable-next-line no-empty-blocks
    constructor(address adapter) BasicRandcastConsumerBase(adapter) {}

    /**
     * Requests randomness
     */
    function getRandomNumberThenGenerateShuffledArray(
        uint256 shuffledArrayUpper,
        uint64 subId,
        uint256 seed,
        uint16 requestConfirmations,
        uint32 callbackGasLimit,
        uint256 callbackMaxGasPrice
    ) external returns (bytes32) {
        bytes memory params;

        uint256 rawSeed = _makeRandcastInputSeed(seed, address(this), nonce);
        // This should be identical to controller generated requestId.
        bytes32 requestId = _makeRequestId(rawSeed);
        shuffledArrayUppers[requestId] = shuffledArrayUpper;

        return _rawRequestRandomness(
            RequestType.Randomness, params, subId, seed, requestConfirmations, callbackGasLimit, callbackMaxGasPrice
        );

        // These equals to following code(recommended):
        // bytes32 requestId = rawRequestRandomness(
        //    RequestType.Randomness,
        //    params,
        //    subId,
        //    seed,
        //    requestConfirmations,
        //    callbackGasLimit,
        //    callbackMaxGasPrice
        // );

        // shuffledArrayUppers[requestId] = shuffledArrayUpper;
    }

    /**
     * Callback function used by Randcast Adapter
     */
    function _fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
        shuffleResults.push(RandcastSDK.shuffle(shuffledArrayUppers[requestId], randomness));
    }

    function lengthOfShuffleResults() public view returns (uint256) {
        return shuffleResults.length;
    }
}
```

In `getRandomNumberThenGenerateShuffledArray` function, before requesting randomness, you can have more flexibility.  For example, you can pass the user seed as input parameter, and calculate the raw seed and request id of the next randomness request before actually calling the `_rawRequestRandomness` function.&#x20;

Also, you can set `subId`, `requestConfirmations`, `callbackGasLimit`, and `callbackMaxGasPrice` specifically for each randomness request.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.arpanetwork.io/randcast/using-the-sdk/consumer-contract-examples/example-advanced-request.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
