Posts

Showing posts from December, 2025

Thoughts on Random Number Generation - QuickCheck

Image
This post was first published on  15 October 2020, but that site has since been shut down. Photo by Frank H Jung Part 1  of this series explored pseudo-random values—statistically random values derived from a known starting point. This article explores using random values in testing. Randomness in test invocation is common; for instance,  JUnit5  provides an annotation to  randomise the order of test execution . This article, however, examines a testing style using randomly generated input values to test  properties  of code, known as “Property Based Testing”. Why use random values in testing? Defining suitable positive and negative test cases to exercise code is often difficult. Automating the execution of many randomly selected tests covers a broader range of input values. Furthermore, recording and reporting failing tests allows for replay and debugging. Property-based testing verifies program code using a large range of relevant inputs by generatin...

Thoughts on Random Number Generation - Shell Scripts

Image
This blog was first published in 2019, but the site has since been shut down. One of the first exercises given to me as a mathematics student was to write a random number generator (RNG). This turned out to be not so easy. Test sequences cycled quickly or were too predictable or were not evenly distributed. Typically when we talk of RNG’s we are describing  pseudorandom  number generators. Nowadays, we have a many programs that will generate  pseudorandom  numbers. Where are random numbers used? As a developer they were rarely required. Recently, however we’ve seen them appear in more and more places - it seems they are  everywhere ! In DevOps, I’ve used RNG’s for creating message payloads of arbitrary size, and for file or directory names. These values are often created using scripts written in  bash . This first article will explore three simple RNG’s that can be run from bash. It is not an exhaustive list, as there are others such as  jot  that...