Astarte.Flow.Blocks.RandomProducer (astarte_flow v0.1.0)

Producer module that generates random messages of a specific type with a fixed key. The supported types are :integer, :real and :boolean.

The data generated for each type is the following:

  • :integer generates a random integer between :min and :max (defaults to min = 0 and max = 100).
  • :real generates a random float between :min and :max (defaults to min = 0 and max = 1).
  • :boolean generates true with probability :p (defaults to p = 0.5), otherwise false.

The message timestamp will be generated with DateTime.utc_now().

Link to this section Summary


Starts the RandomProducer.

Link to this section Types

Link to this type


@type boolean_option() :: {:p, float()}
Link to this type


@type integer_option() :: {:min, integer()} | {:max, integer()}
@type option() ::
  {:key, String.t()}
  | {:type, supported_types()}
  | {:delay_ms, integer()}
  | integer_option()
  | real_option()
  | boolean_option()
@type options() :: [option()]
Link to this type


@type real_option() :: {:min, float()} | {:max, float()}
Link to this type


@type supported_types() :: :integer | :real | :boolean

Link to this section Functions

Link to this function


@spec start_link(options()) :: GenServer.on_start()

Starts the RandomProducer.



  • :key (required) - A unicode string that will be used as key in the generated messages
  • :type (required) - The type of data that will be generated. Supported types are :integer, :real and :boolean
  • :min - Used with :integer and :real types to define a min value.
  • :max - Used with :integer and :real types to define a max value.
  • :p - Used with :boolean type to define the probability of the generator returning true. The value must be >= 0 and <= 1.
  • :delay_ms - If not nil, the block will wait delay_ms before emitting a new sample