Browse the docs

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#

silk
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#

silk
pub struct Seed

A seed of two u64 words. Read them with InsecureSeed.first and InsecureSeed.second.

Implementation Copy for Seed#

silk
impl Copy for Seed

InsecureSeed#

silk
pub service InsecureSeed

The 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#

silk
effect fn get() -> Seed ? &InsecureSeed

Returns the seed of the provider. Each read returns the same seed.

Implementation InsecureSeed#

silk
impl InsecureSeed

Associated function first#

silk
pub fn first(seed: &Seed) -> u64

Returns the first word of seed.

Associated function second#

silk
pub fn second(seed: &Seed) -> u64

Returns the second word of seed.

Associated function fixed#

silk
pub fn fixed(first: u64, second: u64) -> FixedInsecureSeed

Returns a provider with the seed first, second. It does not use randomness.

Associated function fromRandom#

silk
pub effect fn fromRandom() -> FixedInsecureSeed ? &mut Random

Returns 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#

silk
pub struct FixedInsecureSeed

A provider that holds one seed. Make one with InsecureSeed.fixed or InsecureSeed.fromRandom.

Implementation FixedInsecureSeed#

silk
impl FixedInsecureSeed

Implementation InsecureSeed for FixedInsecureSeed#

silk
impl InsecureSeed for FixedInsecureSeed

Operation get#

silk
get: FixedInsecureSeed.fixedGet

Category: 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.

View the source of this page