silk.system.insecure_seed.
The InsecureSeed effect: one fixed 128-bit value that a program reads when it starts.
When to use#
Read InsecureSeed.get while you set up a runtime or a data structure that needs a seed, for
example to make hash collisions harder to cause. Provide InsecureSeed.fixed for repeatable
runs, or InsecureSeed.fromRandom when secure randomness is available.
Details#
Each read returns the same Seed. InsecureSeed.fromRandom reads two u64 values from
Random one time and keeps them.
Gotchas#
It is not a sequence of random values and is not secure. The hash collections of the standard
library do not read it. Give them a seed with silk.collections.hash.Hash.seed.
Examples#
Provide a fixed seed#
import silk.core.effect { Effect }
import silk.system.insecure_seed { InsecureSeed }
pub fn main() -> i32 {
let provider = InsecureSeed.fixed(20, 22)
let seed = run InsecureSeed.get() |> Effect.provide<InsecureSeed>(&provider)
if InsecureSeed.first(&seed) + InsecureSeed.second(&seed) != 42 {
return 1
}
return 0
}Import as InsecureSeed with import silk.system.insecure_seed { InsecureSeed }.
Public declarations: 3.
Seed#
pub struct SeedA seed of two u64 words. Read them with InsecureSeed.first and InsecureSeed.second.
Implementation Copy for Seed#
impl Copy for SeedInsecureSeed#
pub service InsecureSeedThe effect that returns the same 128-bit Seed on each read. It needs only shared access.
When to use#
Read InsecureSeed.get while you set up a runtime or a data structure that needs a seed, for
example to make hash collisions harder to cause. Provide InsecureSeed.fixed for repeatable
runs, or InsecureSeed.fromRandom when secure randomness is available.
Gotchas#
It is not a sequence of random values and is not secure. The hash collections of the standard
library do not read it. Give them a seed with silk.collections.hash.Hash.seed.
Operation get#
effect fn get() -> Seed ? &InsecureSeedReturns the seed of the provider. Each read returns the same seed.
Implementation InsecureSeed#
impl InsecureSeedAssociated function first#
pub fn first(seed: &Seed) -> u64Returns the first word of seed.
Associated function second#
pub fn second(seed: &Seed) -> u64Returns the second word of seed.
Associated function fixed#
pub fn fixed(first: u64, second: u64) -> FixedInsecureSeedReturns a provider with the seed first, second. It does not use randomness.
Associated function fromRandom#
pub effect fn fromRandom() -> FixedInsecureSeed ? &mut RandomReturns a provider with a seed from two u64 values of Random. It reads Random one time,
and the provider keeps the same seed after that.
FixedInsecureSeed#
pub struct FixedInsecureSeedA provider that holds one seed. Make one with InsecureSeed.fixed or
InsecureSeed.fromRandom.
Implementation FixedInsecureSeed#
impl FixedInsecureSeedImplementation InsecureSeed for FixedInsecureSeed#
impl InsecureSeed for FixedInsecureSeedOperation get#
get: FixedInsecureSeed.fixedGetCategory: System.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.