Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
sim:start [2022/07/17 06:10]
rajit [Exported processes]
sim:start [2022/07/17 06:15]
rajit [Namespace sim::rand]
Line 41: Line 41:
  
 ===== Namespace sim::rand ===== ===== Namespace sim::rand =====
 +
 +The ''sim::rand'' namespace contains support for random number generation, and includes the definition of a random source.
 +
 +<code act>
 +export template<pint W>
 +defproc source(chan!(int<W>) O);
 +</code>
 +This defines a source whose output is generated using the underlying C library's pseudo-random number generator.
 +
 +<code act>
 +export function init(int<8> width) : int<32>;
 +export function init_range(int<8> width; int<32> minval, maxval) : int<32>;
 +</code>
 +These functions are used to initialize a (pseudo) random number generator. They return an identifier to be used in subsequent calls to the functions below to access the generator. The first one initializes a random number generator of the specified bit-width, while the second one specifies an interval over which the random number is supposed to be uniformly distributed.
 +
 +<code act>
 +export function get(int<32> idx) : int<64>;
 +</code>
 +Returns the next random number from the generator specified by index ''idx''.
 +
 +<code act>
 +export function seed(int<32> idx; int<32> val) : bool;
 +</code>
 +Set the seed for the random number generator ''idx'' to the value ''val''.
 +