Trait anagolay_runtime::Randomness
source · [−]pub trait Randomness<Output> {
fn random(subject: &[u8]) -> Output;
fn random_seed() -> Output { ... }
}
Required methods
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"[..])
.
Provided methods
fn random_seed() -> Output
fn random_seed() -> Output
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.
Implementations on Foreign Types
sourceimpl<Output> Randomness<Output> for TestRandomness where
Output: Decode + Default,
impl<Output> Randomness<Output> for TestRandomness where
Output: Decode + Default,
sourceimpl<T> Randomness<<T as Config>::Hash> for Module<T> where
T: Config,
impl<T> Randomness<<T as Config>::Hash> for Module<T> where
T: Config,
sourcepub fn random(subject: &[u8]) -> <T as Config>::Hash
pub fn random(subject: &[u8]) -> <T as Config>::Hash
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
.