src/math/random.bend
bend-collections@1.0.0.0 · 93 lines · 16 definitions
1import Base
2import bend-collections@1.0.0.0/src/math/u64.bend as W
3import bend-collections@1.0.0.0/src/math/f64.bend as F
4import bend-collections@1.0.0.0/src/math/random/rand.bend as R
5import bend-collections@1.0.0.0/src/math/random/chacha8.bend as C8
6import bend-collections@1.0.0.0/src/math/random/pcg.bend as P
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47def chacha8(+seed: List<&2, U32>) -> Maybe<&2, C8.ChaCha8>:
48 C8.new(seed)
49
50def chacha8_next(g: C8.ChaCha8) -> W.U64 & C8.ChaCha8:
51 C8.next(g)
52
53def pcg(+seed1: W.U64, +seed2: W.U64) -> P.PCG:
54 P.new(seed1, seed2)
55
56def pcg_next(p: P.PCG) -> W.U64 & P.PCG:
57 P.next(p)
58
59def uint64(~S: Data, ~next: S -> W.U64 & S, s: S) -> W.U64 & S:
60 R.uint64(~S, ~next, s)
61
62def uint32(~S: Data, ~next: S -> W.U64 & S, s: S) -> U32 & S:
63 R.uint32(~S, ~next, s)
64
65def int64(~S: Data, ~next: S -> W.U64 & S, s: S) -> W.U64 & S:
66 R.int64(~S, ~next, s)
67
68def int32(~S: Data, ~next: S -> W.U64 & S, s: S) -> U32 & S:
69 R.int32(~S, ~next, s)
70
71def uint64n(~S: Data, ~next: S -> W.U64 & S, s: S, +n: W.U64) -> W.U64 & S:
72 R.uint64n(~S, ~next, s, n)
73
74def uint_below(~S: Data, ~next: S -> W.U64 & S, s: S, +n: W.U64) -> W.U64 & S:
75 R.uint64n(~S, ~next, s, n)
76
77def uint32n(~S: Data, ~next: S -> W.U64 & S, s: S, +n: U32) -> U32 & S:
78 R.uint32n(~S, ~next, s, n)
79
80def intn(~S: Data, ~next: S -> W.U64 & S, s: S, +n: Nat) -> Nat & S:
81 R.intn(~S, ~next, s, n)
82
83def int_range(~S: Data, ~next: S -> W.U64 & S, s: S, +lo: Nat, +hi: Nat) -> Nat & S:
84 R.int_range(~S, ~next, s, lo, hi)
85
86def float64(~S: Data, ~next: S -> W.U64 & S, s: S) -> F.F64 & S:
87 R.float64(~S, ~next, s)
88
89def shuffle(~A: Data, ~S: Data, ~next: S -> W.U64 & S, s: S, +xs: List<&2, A>) -> List<&2, A> & S:
90 R.shuffle(~A, ~S, ~next, s, xs)
91
92def perm(~S: Data, ~next: S -> W.U64 & S, s: S, +n: Nat) -> List<&2, Nat> & S:
93 R.perm(~S, ~next, s, n)