interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / physics0 / pd0_rng.om

80 lines · 1709 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note src/physics0/pd0_rng.om: PD-0 deterministic SplitMix64, FNV-1a64, uniform, const, Irwin-Hall noise, and exact micro-unit multiply.
3note Learner-side safe: no generator, no world, no file I/O.
4
5fn pd0_fnv1a64 tag view uchar * to ulong
6h = ulong 0xcbf29ce484222325
7n = len tag
8for i ulong n bound 256
9h = xor h ulong get tag i
10h = mul h ulong 0x100000001b3
11end
12ret h
13end
14
15fn pd0_splitmix64 r edit ulong 1 to ulong
16s = add get r 0 ulong 0x9e3779b97f4a7c15
17put r 0 s
18z = mul xor s shr s 30 ulong 0xbf58476d1ce4e5b9
19z = mul xor z shr z 27 ulong 0x94d049bb133111eb
20ret xor z shr z 31
21end
22
23fn pd0_stream r edit ulong 1 seed ulong tag view uchar * to void
24h = pd0_fnv1a64 tag
25put r 0 xor seed h
26ret
27end
28
29fn pd0_uniform r edit ulong 1 to long
30v = pd0_splitmix64 r
31ret long rem v ulong 1000001
32end
33
34fn pd0_const r edit ulong 1 lo long hi long to long
35u = pd0_uniform r
36span = sub hi lo
37ret add lo pd0_mul span u
38end
39
40fn pd0_noise r edit ulong 1 sigma_micro long to long
41u1 = pd0_uniform r
42u2 = pd0_uniform r
43u3 = pd0_uniform r
44u4 = pd0_uniform r
45s = sub add add u1 u2 add u3 u4 long 2000000
46ret div mul s sigma_micro PD0_IH_SD
47end
48
49fn pd0_abs_u64 x long to ulong
50if lt x 0
51ret ulong neg x
52end
53ret ulong x
54end
55
56fn pd0_mul a long b long to long
57note Exact (a * b) / 1000000 truncating toward zero without i64 intermediate overflow.
58neg_res = false
59if lt a 0
60neg_res = not neg_res
61end
62if lt b 0
63neg_res = not neg_res
64end
65ua = pd0_abs_u64 a
66ub = pd0_abs_u64 b
67m = ulong 1000000
68qa = div ua m
69ra = rem ua m
70qb = div ub m
71rb = rem ub m
72t0 = mul mul qa qb m
73t1 = add mul qa rb mul qb ra
74t2 = div mul ra rb m
75res = add add t0 t1 t2
76if neg_res
77ret neg long res
78end
79ret long res
80end