Trait subsocial_runtime::Randomness[][src]

pub trait Randomness<Output> {
    pub fn random(subject: &[u8]) -> Output;

    pub fn random_seed() -> Output { ... }
}

Required methods

pub fn random(subject: &[u8]) -> Output[src]

Get a “random” value

Being a deterministic blockchain, real randomness is difficult to come by. This gives you something that approximates it. At best, this will be randomness which was hard to predict a long time ago, but that has become easy to predict recently.

subject is a context identifier and allows you to get a different result to other callers of this function; use it like random(&b"my context"[..]).

Loading content...

Provided methods

pub fn random_seed() -> Output[src]

Get the basic random seed.

In general you won’t want to use this, but rather Self::random which allows you to give a subject for the random result and whose value will be independently low-influence random from any other such seeds.

Loading content...

Implementations on Foreign Types

impl<Output> Randomness<Output> for TestRandomness where
    Output: Default + Decode
[src]

impl<T> Randomness<<T as Trait>::Hash> for Module<T> where
    T: Trait
[src]

pub fn random(subject: &[u8]) -> <T as Trait>::Hash[src]

This randomness uses a low-influence function, drawing upon the block hashes from the previous 81 blocks. Its result for any given subject will be known far in advance by anyone observing the chain. Any block producer has significant influence over their block hashes bounded only by their computational resources. Our low-influence function reduces the actual block producer’s influence over the randomness, but increases the influence of small colluding groups of recent block producers.

WARNING: Hashing the result of this function will remove any low-influence properties it has and mean that all bits of the resulting value are entirely manipulatable by the author of the parent block, who can determine the value of parent_hash.

Loading content...

Implementors

Loading content...