Rvs is a C API library for defining and evaluating random variables using a simple DSL (Domain Specific Language).
```C // An enumeration defintion with implicit value members. enum Command { Read, Write, Erase, }
// A variable that yields the repeating pattern: 2, 0, 1, 0 pattern = Pattern( Command::Erase, Command::Read, Command::Write, Command::Read, );
// A variable that yields random values in the range [0, 7] inclusive range = [0, 7];
// A variable that yields random values in the set {0, 1, 2}. Yielded values // are added back to the set. samplewithreplacement = r{ Command::Read, Command::Write, Command::Erase, };
// A variable that yields random values in the set {0, 1, 2}. Yielded values // are removed from the set. After all values have been yielded, the set is // repopulated. samplewithoutreplacement = { Command::Read, Command::Write, Command::Erase, };
// A variable that yields weighted random values 0 40% of the time, 1 50%
// of the time, and 2 10% of the time.
weightedsamplewith_replacement = r{
40: Command::Read,
50: Command::Write,
10: Command::Erase,
};
// A variable that randomly yields values from a pool of 40 0s, 50 1s, and
// 10 2s. Yielded values are removed from the pool. The pool is
// re-populated after all values have been yielded.
weightedsamplewithout_replacement = {
40: Command::Read,
50: Command::Write,
10: Command::Erase,
};
```
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
[ ] Expr features
next()prev()done()reset()Display[x] Parse from string
C API
rvs_context_new()rvs_context_free()rvs_seed()rvs_parse()rvs_get()rvs_next()rvs_done()rvs_prev()rvs_reset()rvs_write_definitions()Grammar
enum Enum { Value, }enum Enum { Value = 0, }enum Enum { Value = 0, } a =
Enum::Value expands to a = 0enum Enum { Value0, Value1, } a =
Sample(Enum) expands to a = Sample(0, 1)<identifier><identifier>.copy<identifier>.prev<expr>.done<expr>.onceExpand(<expr>) OR Expand(<expr>, <count-expr>)[<lower>, <upper>]r{<weight>: <expr>, ...}
r{<expr>, ...}
{<weight>: <expr>, ...}
{<expr>, ...}
Pattern(<expr>, ...)
Sequence(<count>) OR
Sequence(<offset>, <count>) OR
Sequence(<offset>, <increment>, <count>)::key0::path::file => '/a/b/c/path/file.rvs'path::file => ['/a/b/c/path/file.rvs', '/d/e/f/path/file.rvs']import fileb in filea becomes $(dirname filea)/fileb.rvspath::file instead of 'path/file.rvs'HashMap<String, Box<Expr>> to HashMap<&str, Box<Expr>>RangeInclusive with
rand::distributions::Range::new_inclusive()Iterator trait