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