pub fn random_int32(args: &HashMap<String, Value>) -> Result<Value>Expand description
A Tera function to generate a random signed 32-bit integer.
The start parameter takes a signed 32-bit integer to indicate the beginning of the
range (inclusive). If start is not passed in, it defaults to i32::MIN.
The end parameter also takes an signed 32-bit integer indicating the end of the range,
which is also inclusive. An inclusive range allows i32::MAX to be sampled where an
exclusive range does not. If end is not passed in, it defaults to i32::MAX.
It is possible to pass in both start and end, just one of them, or neither in order to
sample across the entire i32 space.
§Example usage
ⓘ
use tera::{Context, Tera};
use tera_rand::random_int32;
let mut tera: Tera = Tera::default();
tera.register_function("random_int32", random_int32);
let context: Context = Context::new();
// bound by both start and end
let rendered: String = tera
.render_str("{{ random_int32(start=-128, end=127) }}", &context)
.unwrap();
// bound by just start
let rendered: String = tera
.render_str("{{ random_int32(start=1) }}", &context)
.unwrap();
// bound by just end
let rendered: String = tera
.render_str("{{ random_int32(end=-1) }}", &context)
.unwrap();
// bound by neither start nor end
let rendered: String = tera
.render_str("{{ random_int32() }}", &context)
.unwrap();