Random function

I want to generate number in specified range through random function what will be argument should be passed in the function ?

random() function gets you a random number between 0 and 1, it doesnt require any arguments (but maybe there are some optional parameters that I am unaware of).

Then you can multiply the by another number to set a different limit.
People often also use the "once(random())" function in order to avoid this number changing as the user navigates around the form.

1 Like

https://docs.getodk.org/form-operators-functions/#random has more on how random works and how to use it properly.

Thanks for your reply. I am wondering is there any way(function or method) to generate fix digit numbers in specific range?

Hi Raushan,

Once you get a random number using once(random()), and then use standard mathematical operators (+, -, *, div) to adjust the result to your desired range, you can then round the result to your preferred number of digits using the "round()" function.

For example a 3 digit random number between 2 and 7 would be something like this: round(once(random())*5+2, 3)
The order of the functions does matter, this order should give an accurate result.

More info on rounding below:
https://docs.getodk.org/form-operators-functions/#round

2 Likes