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.

Link to this function

date(rand_state, start_date, end_date)

View Source

Returns updated rand_state and random date between given start and end date.

Link to this function

datetime(rand_state, start_date, end_date)

View Source

Picks a random date/datetime d such that start_date <= d < end_date. Returns {new_rand_state, d}.

Link to this function

decimal(rand_state, min, max, scale)

View Source

Returns a tuple {new_rand_state, d}, where d is a decimal with min <= d < max.

Link to this function

export_rand_state(rand_state)

View Source
@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.

Link to this function

float(rand_state, min, max)

View Source

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.

Link to this function

init_rand_state(rand_state)

View Source
@spec init_rand_state(rand_state()) :: rand_state()

Recreates a particular rand_state from the output of export_rand_state/1.

Link to this function

integer(rand_state, min, max)

View Source

Returns a tuple {new_rand_state, i}, where min <= i < max.

Link to this function

list_element(rand_state, list)

View Source
@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.

Link to this function

stream(module, rand_state)

View Source
@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.

Link to this function

string(rand_state, max_length \\ 1000, min_codepoint \\ 0, max_codepoint \\ 10000)

View Source
Link to this function

time(rand_state, start_time, end_time)

View Source