The AdvancedGetShuffledArrayExample shows how to request and consume randomness of type Shuffling without extending GeneralRandcastConsumerBase.
// SPDX-License-Identifier: MITpragmasolidity ^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-importimport"randcast-user-contract/user/RandcastSDK.sol" as RandcastSDK;contractAdvancedGetShuffledArrayExampleisRequestIdBase, BasicRandcastConsumerBase, RandomnessHandler {mapping(bytes32=>uint256) public shuffledArrayUppers;uint256[][] public shuffleResults;// solhint-disable-next-line no-empty-blocksconstructor(address adapter) BasicRandcastConsumerBase(adapter) {}/** * Requests randomness */functiongetRandomNumberThenGenerateShuffledArray(uint256 shuffledArrayUpper,uint64 subId,uint256 seed,uint16 requestConfirmations,uint32 callbackGasLimit,uint256 callbackMaxGasPrice ) externalreturns (bytes32) {bytesmemory 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) internaloverride { shuffleResults.push(RandcastSDK.shuffle(shuffledArrayUppers[requestId], randomness)); }functionlengthOfShuffleResults() publicviewreturns (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.
Also, you can set subId, requestConfirmations, callbackGasLimit, and callbackMaxGasPrice specifically for each randomness request.