Randomness
How do we ensure that the generation of residents is completely random?
Just like many fair dApps (games) on the Sui, we use DRAND randomness solution to ensure that the process of generating Dungeon Residents is completely random and in accordance with the corresponding probabilities.
This also guarantees that no one can control this process, so the residents obtained by opening treasure chests are completely random.
Drand Chain Info (quicknet)
// Currently works with chain
// 52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971 (quicknet).
/// The genesis time of chain 52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971.
const GENESIS: u64 = 1692803367;
/// The public key of chain 52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971.
const DRAND_PK: vector<u8> =
x"83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a";
/// The time in seconds between randomness beacon rounds.
const PERIOD: u64 = 3;
In `reveal_treasure` ,
// A code snippet that use DRAND randomness
public entry fun reveal_treasure(....) {
drand_lib::verify_drand_signature(drand_sig, reveal_round(treasure_key.purchased_round));
let random_key = drand_lib::derive_randomness(drand_sig);
let randomness = hmac_sha3_256(&random_key, &object::id_to_bytes(&object::id(&treasure_key)));
...
}
In the settlement of the Boss Cave and the calculation of Gem probabilities, we utilize Sui's On-Chain Randomness feature to ensure absolute fairness.
For more technical details, please refer to On-Chain Randomness
Last updated
Was this helpful?