I have a test program where I need to generate a random number. I therefore did a test comparing using
"uVal = rand::task_rng().gen();"
each time a random number is generated compared to creating an object using eg. :
let mut oRandom = std::rand::task_rng()
and generating multiple random numbers. Using the object (oRandom) created is much faster, so I thought I should pass the object to the function generating the random number, however I haven't been able to find a way to do that. It's not critical, but I presume it can be done.
Example 1 : not using the object : (much slower than 2)
let mut uVal : u8;
for _ in range(1, iMax) {
uVal = std::rand::task_rng().gen();
Example 2 : using the object : (much faster than 1)
let mut oRandom = std::rand::task_rng();
let mut uVal : u8;
for _ in range(1, iMax) {
uVal = oRandom.gen();
Example 3 : my attempt to pass the object to the function :
12 let mut oRandom = std::rand::task_rng();
13 fTest03(iMax, &mut oRandom);
53 fn fTest03(iMax : i64, oRandom : &mut std::rand::task_rng) {
This results in the following error :
test_rand003.rs:53:38: 53:57 error: use of undeclared type name
`std::rand::task_rng`
test_rand003.rs:53 fn fTest03(iMax : i64, oRandom : &mut std::rand::task_rng) {
How can I pass the variable "oRandom" in line 13 above to a function?