[Haskell-cafe] Random pattern generation with list comprehensions

Mike Jones mike at proclivis.com
Fri Dec 12 23:48:10 UTC 2014


I am looking for a way to generate random patterns for hardware validation. The goal is to separate patten generation from execution in hardware, and from pure code used to compute expected behavior from a model, detection of bad behavior, in the form of predicates, etc. The purpose of random patterns is to explore the behavior space in less time, as well as improve time to discovery by preventing long runs that focus in narrow areas for long periods. Patterns are to be infinite lists with the ability to specify run length for any run, which becomes a quality dial of sorts.

I initially started with finite sequences expressed as list comprehensions, that generate tuples of ints, floats, structured data, and lists of attributes (bit combinations of hardware registers).

I believe the list comprehension evaluates each generator (a | a <- ...) in a strict order, such that an infinite list will cause infinite evaluation of a single generator, such that other generators are not evaluated. Even if each generator is constrained (take n), results will not not be completely random.

What I need is for each generator to supply one value each, and combine them into a tuple.

I could probable express this in a monadic loop construct, as long as each generator is random and holds state, like the article I saw using the State Monad to generate random numbers. Or perhaps a State monad that holds multiple generators.

Is there a better way to express the solution or a helpful module others use for this?

Mike

Sent from my iPad


More information about the Haskell-Cafe mailing list