aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/fun/rng-state.bruijn
blob: 2297728a5e1933a1fceebd33e7072d33857f58e8 (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]] [[[0]]]) =? (+595)) ([[1]])

main string→number → triple → &[[1]]