random_uint32

Function random_uint32 

Source
pub fn random_uint32(args: &HashMap<String, Value>) -> Result<Value>
Expand description

A Tera function to generate a random unsigned 32-bit integer.

The start parameter takes an unsigned 32-bit integer to indicate the beginning of the range (inclusive). If start is not passed in, it defaults to u32::MIN.

The end parameter also takes an unsigned 32-bit integer indicating the end of the range, which is also inclusive. An inclusive range allows u32::MAX to be sampled where an exclusive range does not. If end is not passed in, it defaults to u32::MAX.

It is possible to pass in both start and end, just one of them, or neither in order to sample across the entire u32 space.

§Example usage

use tera::{Context, Tera};
use tera_rand::random_uint32;

let mut tera: Tera = Tera::default();
tera.register_function("random_uint32", random_uint32);
let context: Context = Context::new();

// bound by both start and end
let rendered: String = tera
    .render_str("{{ random_uint32(start=49152, end=65535) }}", &context)
    .unwrap();
// bound by just start
let rendered: String = tera
    .render_str("{{ random_uint32(start=4294967290) }}", &context)
    .unwrap();
// bound by just end
let rendered: String = tera
    .render_str("{{ random_uint32(end=65535) }}", &context)
    .unwrap();
// bound by neither start nor end
let rendered: String = tera
    .render_str("{{ random_uint32() }}", &context)
    .unwrap();