Comment by orthecreedence
2 days ago
Lately I've been working on a testing system for a DAG identity system I'm working on. The system tries thousands of permutations of DAG setups, all driven from a random seed. In other words, it's entirely repeatable and deterministic each time. If something breaks, I can pinpoint the exact run and re-run it with the exact same parameters.
It took a long time to get there. One of the main things I had root out, time after time, was the use of HashMap/HashSet (this is in rust) which I converted to BTreeMap/BTreeSet because the former are not deterministic when iterating over them, causing all kinds of random permutations for a given seed. I knew this going in, but kind of surprised myself how often I almost absentmindedly reached for a non-deterministic data type when determinism was important.
The non-determinism of Rust's HashMap/HashSet is because the default hasher seeds itself using the operating system's RNG facilities. You can use the with_hasher() function to replace the default hasher with a PRNG that is deterministically seeded.