[ODK Developers] random() function behavior

There is a work-around:

Instead of:

do this:

I.e., add nonsense math, changing the 0.1 to a different value for each of
the fields that use random(), making the calculate expressions different
from every other calculate in the form.

The underlying problem is that javarosa (the XForms interpreter
underpinning ODK Collect) attempts to consolidate calculate expressions and
only evaluate them once, sharing that one computed value across all uses in
the form (this is called common sub-expression elimination).
Unfortunately, the logic does not take into account that successive calls
to random() and uuid() are never identical, and therefore cannot be

Fortunately, javarosa only consolidates top-level expressions, and not
nested ones, so the adding and subtracting of the same nonsense value is
enough to fool it into doing the right thing.

I've opened a bug against javarosa (the XForms interpreter underpinning ODK
Collect) for this:


ยทยทยท On Fri, Feb 1, 2013 at 5:01 PM, wrote:

Hi all:

I'm trying to use the random() function and find that it generates the
same value w/in any one form instance no matter how many times/places I
call it. Is that the expected behavior? Cannot find any documentation on
it other than the Binding page (

I've attached a form that demonstrates the problem.


You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mitch Sundt
Software Engineer
University of Washington