rnd_seed.rs

Overview

This file defines the RndSeed struct, representing a fixed-size 32-byte random seed used primarily for deterministic pseudorandom computations related to block processing. The seed supports serialization/deserialization, hashing, comparison, and bitwise operations, enabling its use as a cryptographic or deterministic random value in the system.

The core functionality includes:

The RndSeed plays a role in how blocks and identifiers are processed, likely within consensus or block selection mechanisms, interacting particularly with the BlockIdentifier type.


Structs and Implementations

RndSeed

Definition

pub struct RndSeed([u8; 32]);

Encapsulates a 32-byte array representing a random seed.

Derives

Attributes


Methods

not_a_modulus(&self, divider: u32) -> u32

let seed = RndSeed::from([0u8; 32]);
let bucket = seed.not_a_modulus(10); // returns a value between 0-9

Trait Implementations

Debug & LowerHex Formatting

Example:

println!("{:?}", seed);       // prints hex string
println!("{:#x}", seed);      // prints 0x-prefixed hex string

From<[u8; 32]> for RndSeed

Example:

let bytes = [0u8; 32];
let seed = RndSeed::from(bytes);

AsRef<[u8]> for RndSeed

Example:

let bytes_ref: &[u8] = seed.as_ref();

FromStr for RndSeed

Example:

let seed: RndSeed = "0xabcdef...".parse()?;

BitXor<BlockIdentifier> for RndSeed

Example:

let new_seed = seed ^ block_identifier;

Important Implementation Details


Interaction With Other Components


Diagram: Structure and Functionality of RndSeed

classDiagram
class RndSeed {
- bytes: [u8; 32]
+ not_a_modulus(divider: u32): u32
+ from_str(value: &str) -> Result<RndSeed, Error>
+ as_ref() -> &[u8]
+ bitxor(BlockIdentifier) -> RndSeed
+ fmt::Debug
+ fmt::LowerHex
}
RndSeed ..> BlockIdentifier : bitxor with
RndSeed ..> [u8;32] : contains