Skip to content
Snippets Groups Projects

support proper 32-byte RNG seeds

Merged STEVAN Antoine requested to merge rng into main
1 file
+ 49
1
Compare changes
  • Side-by-side
  • Inline
+ 49
1
use consts.nu
use ../../.nushell cargo "cargo bin"
use ../../.nushell error "error throw"
const VALID_HEX_CHARS = "abcdefABCDEF0123456789"
def check-hex [-n: int]: [
string -> record<
ok: bool,
err: record<msg: string, label: string, help: string>,
>
] {
let s = $in
if ($s | str length) != $n {
return {
ok: false,
err: {
msg: "invalid HEX length"
label : $"length is ($s | str length)",
help: "length should be 64",
},
}
}
for c in ($s | split chars | enumerate) {
if not ($VALID_HEX_CHARS | str contains $c.item) {
return {
ok: false,
err: {
msg: "bad HEX character",
label: $"found '($c.item)' at ($c.index)",
help: $"expected one of '($VALID_HEX_CHARS)'",
},
}
}
}
{ ok: true, err: {} }
}
export def main [
--options: record<
@@ -14,7 +52,7 @@ export def main [
strategies: list<string>,
environment: string,
>,
--prng-seed: int = 0,
--prng-seed: string = "0000000000000000000000000000000000000000000000000000000000000000",
] {
if $options.measurement_schedule_start > $options.max_t {
error make --unspanned {
@@ -22,6 +60,16 @@ export def main [
}
}
let res = $prng_seed | check-hex -n 64
if not $res.ok {
error throw {
err: $res.err.msg,
label: $res.err.label,
span: (metadata $prng_seed).span,
help: $res.err.help,
}
}
let now = date now | format date "%s%f"
for s in $options.strategies {
Loading