std/random
deterministic randomness
Phrases
random.Pick [l: list of value]
A uniformly chosen item; an index-range run-time error on an empty list
- Gives
- item type of `l`
- Contexts
- node, main
- Kind
- phrase, native
- Source
- random/random.synod:3
- Examples
- random/dice
random.Between [a: number] and [b: number]
Uniform in [a, b)
- Gives
- number
- Contexts
- node, main
- Kind
- phrase, native
- Source
- random/random.synod:6
- Examples
- random/dice
random.TimeBetween [a: time] and [b: time]
Uniform in [a, b), whole microseconds
- Gives
- time
- Contexts
- node, main
- Kind
- phrase, native
- Source
- random/random.synod:9
- Examples
- random/dice
random.Chance [p: number]
True with probability p
- Gives
- bool
- Contexts
- node, main
- Kind
- phrase, native
- Source
- random/random.synod:12
- Examples
- random/dice
Examples
dice
Shows random.Between, random.Pick, random.TimeBetween and random.Chance; try another seed with --seed
# package main
# Shows random.Between, random.Pick, random.TimeBetween and random.Chance; try another seed with --seed
use example.com/library/random/dice
use std/random
use std/sim
define main
sim.Seed 42
set group to (sim.Cluster of 3 running dice)
after (random.TimeBetween 1s and 2s)
sim.Crash (random.Pick group)
sim.StopAt 4s
# package dice
use std/random
Node has
set Roll to 0
set Pick to ""
set Lucky to false
set Wait to 0s
# Each draw comes from the run's seed, so the same seed gives the same run
define [n: Node] start
set n.Roll to (random.Between 1 and 6)
set n.Pick to (random.Pick {"red", "green", "blue"})
set n.Lucky to (random.Chance 0.25)
set n.Wait to (random.TimeBetween 1s and 3s)
after n.Wait
set n.Roll to (random.Between 1 and 6)