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
Previous revision
Next revision Both sides next revision
sim:start [2022/07/17 06:08]
rajit
sim:start [2022/07/17 06:15]
rajit [Namespace sim::rand]
Line 39: Line 39:
 </code> </code>
 This process is a ''W''-bit sink, except the values produced are compared to those specified in a file. The identified ''ID'' is used to determine the file name, and the file is assumed to have at least one data value. The file specified and the ''LOOP'' parameter is the same as in ''file_source''. This process is a ''W''-bit sink, except the values produced are compared to those specified in a file. The identified ''ID'' is used to determine the file name, and the file is assumed to have at least one data value. The file specified and the ''LOOP'' parameter is the same as in ''file_source''.
 +
 +===== 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''.
 +