pub fn random_float32(args: &HashMap<String, Value>) -> Result<Value>Expand description
A Tera function to generate a random 32-bit float.
By default, it generates a float between 0.0 and 1.0.
The start parameter takes a 32-bit float to indicate the beginning of the
range (inclusive). If start is not passed in, it defaults to 0.0.
The end parameter also takes a 32-bit float indicating the end of the range,
which is inclusive in order to remain consistent with the rest of the Tera functions.
If end is not passed in, it defaults to 1.0.
It is possible to pass in both start and end, just one of them, or neither.
§Example usage
ⓘ
use tera::{Context, Tera};
use tera_rand::random_float32;
let mut tera: Tera = Tera::default();
tera.register_function("random_float32", random_float32);
let context: Context = Context::new();
// bound by both start and end
let rendered: String = tera
.render_str("{{ random_float32(start=-4096.0, end=4096.0) }}", &context)
.unwrap();
// bound by just start
let rendered: String = tera
.render_str("{{ random_float32(start=0.0) }}", &context)
.unwrap();
// bound by just end
let rendered: String = tera
.render_str("{{ random_float32(end=0.0) }}", &context)
.unwrap();
// bound by neither start nor end
let rendered: String = tera
.render_str("{{ random_float32() }}", &context)
.unwrap();