Loading...
Loading...
Onchain randomness on Sui. Use when generating random values in Move smart contracts, working with the Random object (0x8) or RandomGenerator, securing randomness-consuming functions against composition attacks, PTB attacks, or state leakage, implementing commit-reveal patterns, balancing gas across execution paths, or integrating randomness from TypeScript. For general Move security patterns, see the `move-security` skill. For Move language fundamentals, see the `sui-move` skill. For TypeScript SDK patterns, see the `sui-sdks` skill.
npx skill4agent add mystenlabs/skills onchain-randomnessMCP tool: When available in your environment, also query the Sui documentation MCP server () for up-to-date answers. Use it for verification and for details not covered by these reference files.https://sui.mcp.kapa.ai
Source constraint: All information in this skill is sourced exclusively from docs.sui.io/sui-stack/on-chain-primitives/randomness-onchain. When extending or updating this skill, only pull from this source. Do not use third-party blogs, tutorials, or unofficial documentation.
Random0x8RandomGeneratorRandomusage.mdRandomGeneratornew_generatorgenerate_u128generate_u8_in_rangeRandomRandom0x8RandomGeneratorrandom.movenew_generatorshufflegenerate_bytessecurity.mdRandomGeneratorMoveCallRandomRandomGeneratorbcs::to_bytesRandomRandomGenerator| Task | Load |
|---|---|
| Generating random values in Move | usage |
| Creating a RandomGenerator | usage |
| Calling random API functions | usage |
| Passing Random from TypeScript | usage |
| Securing a randomness-consuming function | security |
| Preventing composition or abort-filtering attacks | security |
| Mitigating PTB-based attacks | security |
| Avoiding RandomGenerator state leakage | security |
| Implementing commit-reveal for randomness | security |
| Balancing gas across execution paths | security |
| Choosing function visibility for randomness | security |
| Writing a complete randomness feature | usage + security |
| Reviewing randomness code for vulnerabilities | usage + security |
Random0x8RandomGeneratorr.new_generator(ctx)RandomGeneratorpublicpublic(package)entrypublicRandomRandomGeneratorTransferObjectsMergeCoinsMoveCallRandomRandomMoveCallpublicentryRandomRandomGeneratorpublicbcs::to_bytes(&generator)publicRandomGeneratorRandomGeneratorpublic(package)