Published 12th of February, 2016, by Nikos Baxevanis. Tagged as f#, quickcheck.

Write you some QuickCheck - Generating random booleans

This post is part of a series of posts on implementing a minimal version of QuickCheck from scratch. The source code is available on GitHub.

In the previous post I’ve generated random characters. In this post, I’ll be doing the same for booleans.

Two generators are required for this, which have been ported already on previous posts:

Given the above, a boolean generator can be written as:

let bool =
    Gen.oneof [ Gen.init true
                Gen.init false ]

val bool : Gen<bool>

Finally, here are some sample booleans:

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = true

> Gen.bool |> Gen.generate;;
val it : bool = false

> Gen.bool |> Gen.generate;;
val it : bool = false



Wish to comment?

You can comment on this post on GitHub. Alternatively, you can discuss this post on Twitter or elsewhere with a permalink. Ping me with the link, and I may respond.