aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/fun/rng-state.bruijn
blob: 49d77bc9a3296f2a83065a27b70d43276047ab67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# MIT License, Copyright (c) 2024 Marvin Borner
# generates three pseudo-random integers using a state monad
# printf <seed:number> | bruijn rng-state.bruijn

:import std/Combinator .
:import std/String .
:import std/Number .
:import std/Monad/State .

max (+1000)

rand [[[0 1 1]] rng]
	rng (+1103515245) ⋅ 0 + (+12345) % max

rand-bool map even? rand

# normal bind
triple rand >>= [rand >>= [rand >>= [pure [0 1 2 3]]]]

:test ((triple (+50) [[1]]) =? (+595)) ([[[2]]])

main string→number → triple