Example Contracts
You can deploy this to PulseChain Mainnet and test the RNG function immediately. A demo contract is provided that you can call with the provided ABI.
Test RNG
0x72114bBFfAb7e1159506d40A7BE2a48db5de8E53
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IRNG {
function Generate() external returns (uint64);
}
contract Test {
uint256[] list = new uint256[](6);
address RNGContractAddress = 0xa96BcbeD7F01de6CEEd14fC86d90F21a36dE2143;
IRNG RNGContract = IRNG(RNGContractAddress);
uint256 picked = 0;
constructor() {
list[0] = 0;
list[1] = 1;
list[2] = 2;
list[3] = 3;
list[4] = 4;
list[5] = 5;
}
function shuffle() public returns (uint256[] memory) {
uint256[] memory _list = list;
for (uint256 i = 0; i < list.length; i++) {
uint64 rng = RNGContract.Generate();
uint256 n = i + uint256(keccak256(abi.encodePacked(rng))) % (_list.length - i);
uint256 temp = _list[n];
_list[n] = _list[i];
_list[i] = temp;
}
list = _list;
return list;
}
function shuffleAndPickRandom() public returns (uint256) {
uint256[] memory _list = shuffle();
uint64 rng = RNGContract.Generate();
picked = _list[rng % _list.length];
return picked;
}
function viewList() public view returns (uint256[] memory) {
return list;
}
function viewPicked() public view returns (uint256) {
return picked;
}
}
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "shuffle",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "shuffleAndPickRandom",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "viewList",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "viewPicked",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
}
Last updated