pub struct Random<T: Message = u64> {
pub output: OutputPort<T>,
pub seed: Option<u64>,
}Expand description
A block for generating and sending a random value.
§Block Diagram
block-beta
columns 4
Random space:2 Sink
Random-- "output" -->Sink
classDef block height:48px,padding:8px;
classDef hidden visibility:none;
class Random block
class Sink hidden
§Sequence Diagram
sequenceDiagram
autonumber
participant Random as Random block
participant Random.output as Random.output port
participant BlockA as Another block
Random-->>BlockA: Connect
Random->>BlockA: Message
Random-->>Random.output: Close
Random-->>BlockA: Disconnect
§Examples
§Using the block in a system
System::build(|s| {
let random_generator = s.random::<u64>();
let number_encoder = s.encode_lines();
let stdout = s.write_stdout();
s.connect(&random_generator.output, &number_encoder.input);
s.connect(&number_encoder.output, &stdout.input);
});§Running the block via the CLI
$ protoflow execute Random$ protoflow execute Random seed=42Fields§
§output: OutputPort<T>The port to send the value on.
seed: Option<u64>A parameter for the random seed to use.
Implementations§
Source§impl<T: Message> Random<T>
impl<T: Message> Random<T>
pub fn new(output: OutputPort<T>) -> Self
pub fn with_params(output: OutputPort<T>, seed: Option<u64>) -> Self
Trait Implementations§
Source§impl<T: Message + Default> Block for Random<T>
impl<T: Message + Default> Block for Random<T>
Source§fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
fn execute(&mut self, runtime: &dyn BlockRuntime) -> BlockResult
Executes this block’s computation.
Source§fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
Prepares this block for execution. Read more
Source§impl<T: Message> BlockDescriptor for Random<T>
impl<T: Message> BlockDescriptor for Random<T>
Source§fn inputs(&self) -> Vec<PortDescriptor>
fn inputs(&self) -> Vec<PortDescriptor>
A description of this block’s input ports.
Source§fn outputs(&self) -> Vec<PortDescriptor>
fn outputs(&self) -> Vec<PortDescriptor>
A description of this block’s output ports.
Source§fn parameters(&self) -> Vec<ParameterDescriptor>
fn parameters(&self) -> Vec<ParameterDescriptor>
A description of this block’s parameters.
Source§fn ports(&self) -> Vec<PortDescriptor>
fn ports(&self) -> Vec<PortDescriptor>
A description of this block’s I/O ports.
Source§impl<T: Message> MaybeLabeled for Random<T>
impl<T: Message> MaybeLabeled for Random<T>
Source§impl<T: Message> MaybeNamed for Random<T>
impl<T: Message> MaybeNamed for Random<T>
Source§impl StdioSystem for Random<u64>
impl StdioSystem for Random<u64>
fn build_system(config: StdioConfig) -> Result<System, StdioError>
Auto Trait Implementations§
impl<T> Freeze for Random<T>
impl<T = u64> !RefUnwindSafe for Random<T>
impl<T> Send for Random<T>
impl<T> Sync for Random<T>
impl<T> Unpin for Random<T>where
T: Unpin,
impl<T = u64> !UnwindSafe for Random<T>
Blanket Implementations§
Source§impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
fn as_block_descriptor(&self) -> &dyn BlockDescriptor
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more