#pallet #randomness #frame #flip #collective #random #block

no-std pallet-randomness-collective-flip

FRAME randomness collective flip pallet

27 releases (13 major breaking)

15.0.0 Feb 5, 2023
14.0.0 Feb 1, 2023
13.0.0 Jan 22, 2023
12.0.0 Jan 16, 2023
2.0.0-alpha.5 Mar 24, 2020

#14 in #flip

Download history 754/week @ 2024-03-13 1157/week @ 2024-03-20 1175/week @ 2024-03-27 1104/week @ 2024-04-03 941/week @ 2024-04-10 1123/week @ 2024-04-17 1168/week @ 2024-04-24 963/week @ 2024-05-01 967/week @ 2024-05-08 1079/week @ 2024-05-15 1131/week @ 2024-05-22 1232/week @ 2024-05-29 953/week @ 2024-06-05 851/week @ 2024-06-12 996/week @ 2024-06-19 841/week @ 2024-06-26

3,833 downloads per month
Used in 8 crates (6 directly)

Apache-2.0

14KB
183 lines

Randomness Module

The Randomness Collective Flip module provides a random function that generates low-influence random values based on the block hashes from the previous 81 blocks. Low-influence randomness can be useful when defending against relatively weak adversaries. Using this pallet as a randomness source is advisable primarily in low-security situations like testing.

Public Functions

See the Module struct for details of publicly available functions.

Usage

Prerequisites

Import the Randomness Collective Flip module and derive your module's configuration trait from the system trait.

Example - Get random seed for the current block

use frame_support::traits::Randomness;

#[frame_support::pallet]
pub mod pallet {
    use super::*;
    use frame_support::pallet_prelude::*;
    use frame_system::pallet_prelude::*;

    #[pallet::pallet]
    pub struct Pallet<T>(_);

    #[pallet::config]
    pub trait Config: frame_system::Config + pallet_randomness_collective_flip::Config {}

    #[pallet::call]
    impl<T: Config> Pallet<T> {
        #[pallet::weight(0)]
        pub fn random_module_example(origin: OriginFor<T>) -> DispatchResult {
            let _random_value = <pallet_randomness_collective_flip::Pallet<T>>::random(&b"my context"[..]);
            Ok(())
        }
    }
}

License: Apache-2.0

Dependencies

~11–31MB
~437K SLoC