A walkthrough of building a minimal property-based testing (PBT) library in ~256 lines of Zig, centered on a Finite Random Number Generator (FRNG) abstraction. The key insight is that by pre-generating entropy as a fixed byte slice, you can binary-search for the smallest entropy size that reproduces a failure — effectively minimizing test cases without any knowledge of the system under test. The post covers FRNG primitives (bytes, integers, booleans, bounded ranges, weighted random selection), a simulation harness that feeds entropy to a system under test via stdin in a child process, and a search driver that doubles/halves entropy size to find the minimal failing seed. The approach was used to discover a deep algorithmic flaw in a consensus algorithm implementation.

13m read timeFrom matklad.github.io
Post cover image
Table of contents
FRNGSimulationStepping And RunnigBinary Search the AnswerThe Searcher

Sort: