aboutsummaryrefslogtreecommitdiff
path: root/examples/random
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-04 17:06:09 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-04 17:06:09 -0400
commit0b8074154e2671691050bdb3bcb33245625a056c (patch)
tree1410e0c4e05c6372e876cd08f16d117e12868f41 /examples/random
parentfadcb45baf1274e06cfe37b87655b9146aa52874 (diff)
First working compile of refactor to add explicit typing to declarations
and support untyped empty collections and `none`s
Diffstat (limited to 'examples/random')
-rw-r--r--examples/random/README.md2
-rw-r--r--examples/random/random.tm6
2 files changed, 4 insertions, 4 deletions
diff --git a/examples/random/README.md b/examples/random/README.md
index 697f3f7c..6233c1ba 100644
--- a/examples/random/README.md
+++ b/examples/random/README.md
@@ -110,7 +110,7 @@ A copy of the given RNG.
**Example:**
```tomo
->> rng := RNG.new([:Byte])
+>> rng := RNG.new([])
>> copy := rng:copy()
>> rng:bytes(10)
diff --git a/examples/random/random.tm b/examples/random/random.tm
index 1d6e560b..0a0167ac 100644
--- a/examples/random/random.tm
+++ b/examples/random/random.tm
@@ -4,7 +4,7 @@ use ./sysrandom.h
use ./chacha.h
struct chacha_ctx(j0,j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,j11,j12,j13,j14,j15:Int32; extern, secret):
- func from_seed(seed=[:Byte] -> chacha_ctx):
+ func from_seed(seed:[Byte]=[] -> chacha_ctx):
return inline C : chacha_ctx {
chacha_ctx ctx;
uint8_t seed_bytes[KEYSZ + IVSZ] = {};
@@ -24,10 +24,10 @@ func _os_random_bytes(count:Int64 -> [Byte]):
(Array_t){.length=_$count, .data=random_bytes, .stride=1, .atomic=1};
}
-struct RandomNumberGenerator(_chacha:chacha_ctx, _random_bytes=[:Byte]; secret):
+struct RandomNumberGenerator(_chacha:chacha_ctx, _random_bytes:[Byte]=[]; secret):
func new(seed=none:[Byte], -> @RandomNumberGenerator):
ctx := chacha_ctx.from_seed(seed or _os_random_bytes(40))
- return @RandomNumberGenerator(ctx, [:Byte])
+ return @RandomNumberGenerator(ctx, [])
func _rekey(rng:&RandomNumberGenerator):
rng._random_bytes = inline C : [Byte] {