24 major breaking releases

new 27.0.0 Jan 7, 2025
26.0.0 Sep 25, 2024
25.0.0 Jul 18, 2024
24.0.0 Jul 12, 2024
0.0.0 Feb 2, 2023

#352 in Magic Beans

Download history 301/week @ 2024-09-18 592/week @ 2024-09-25 450/week @ 2024-10-02 521/week @ 2024-10-09 612/week @ 2024-10-16 1109/week @ 2024-10-23 849/week @ 2024-10-30 6967/week @ 2024-11-06 26174/week @ 2024-11-13 25313/week @ 2024-11-20 26582/week @ 2024-11-27 26703/week @ 2024-12-04 22721/week @ 2024-12-11 18084/week @ 2024-12-18 6103/week @ 2024-12-25 18346/week @ 2025-01-01

70,478 downloads per month
Used in 21 crates (9 directly)

Apache-2.0

2.5MB
38K SLoC

DO NOT USE IN PRODUCTION

The produced values do not fulfill the cryptographic requirements for random numbers. Should not be used for high-stake production use-cases.

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_insecure_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_insecure_randomness_collective_flip::Pallet::<T>::random(&b"my context"[..]);
            Ok(())
        }
    }
}

License: Apache-2.0

Release

Polkadot SDK Stable 2412

Dependencies

~19–33MB
~552K SLoC