View Source Avrogen.Util.Random (avrogen v0.8.5)
Helper functions for generating random values.
Summary
Functions
Returns a tuple {new_rand_state, b}, where b is a random boolean.
Returns updated rand_state and random date between given start and end date.
Picks a random date/datetime d such that start_date <= d < end_date. Returns {new_rand_state, d}.
Returns a tuple {new_rand_state, d}, where d is a decimal with min <= d < max.
Exports the rand_state in a simple form that can be passed into init_rand_state/1.
Returns a tuple {new_rand_state, f}, where f is a float with min <= f < max.
Creates a fresh rand_state.
Recreates a particular rand_state from the output of export_rand_state/1.
Returns a tuple {new_rand_state, i}, where min <= i < max.
Creates an infinite stream of random avro instances for a given generated avro record module. Useful for 'fuzz-testing' anything that processes avro data: push large numbers of random instances through the code and see if anything raises an exception.
Creates a random stream with a particular starting rand_state, so an entire stream can be replayed just from the seed.
Types
@type rand_state() :: :rand.state() | :rand.export_state()
Functions
Returns a tuple {new_rand_state, b}, where b is a random boolean.
Returns updated rand_state and random date between given start and end date.
Picks a random date/datetime d such that start_date <= d < end_date. Returns {new_rand_state, d}.
Returns a tuple {new_rand_state, d}, where d is a decimal with min <= d < max.
@spec export_rand_state(rand_state()) :: rand_state()
Exports the rand_state in a simple form that can be passed into init_rand_state/1.
Returns a tuple {new_rand_state, f}, where f is a float with min <= f < max.
@spec init_rand_state() :: rand_state()
Creates a fresh rand_state.
@spec init_rand_state(rand_state()) :: rand_state()
Recreates a particular rand_state from the output of export_rand_state/1.
Returns a tuple {new_rand_state, i}, where min <= i < max.
@spec stream(atom()) :: Enumerable.t()
Creates an infinite stream of random avro instances for a given generated avro record module. Useful for 'fuzz-testing' anything that processes avro data: push large numbers of random instances through the code and see if anything raises an exception.
Each element in the stream is a tuple {rand_state, instance}, where rand_state is the random number generator state that was used to create the instance. Feeding this rand_state into the AvroRecordModule's random_instance function will re-create the instance.
@spec stream(atom(), rand_state()) :: Enumerable.t()
Creates a random stream with a particular starting rand_state, so an entire stream can be replayed just from the seed.