Create random data from custom type
问题 I have the following custom type defined data Tree = Empty | Node Tree Tree I want to create random Tree s with a given number of nodes n that I can then pass to another function which calculates the depth of the tree depth :: Tree -> Int depth Empty = 0 depth Node t1 t2 = (maximum [depth t1, depth t2]) + 1 Which is the easiest way to achieve this? EDIT: I have tried with an approach similar to that of Alec in an answer below, which returns a random IO Tree . However, there are several other