Random numbers are the same by device

I have an XLSForm that uses once(random()) with a following calculation, "int(${randNum}*${hhSize})+1" to select a random individual within a household. However, in reviewing the first data today, it's clear that the random number selected in once(random()) is the same for all instances submitted by the same tablet. So each enumerator has submitted four instances so far, and each random number in the data repeats four times. We are using ODK 1.14.0. I've also raised this on GitHub - there's an example form there.

In the immediate term, is there any alternative means of generating a random number I can use? We have already started data collection now so any thoughts would be gratefully received. Not sure what to do as this seems to be the recommended way to generate random numbers?

Small update - I did find a workaround for the time being by adapting this previous suggestion. The random number takes the seconds field of the start time like so:

int(format-date-time(${start}, "%S")) div 60

Which I believe will generate a close-enough-to-random number between 0 & 1.

1 Like

This is very odd indeed, thank you for reporting, @Bramleyl.

I have filed an issue at https://github.com/opendatakit/javarosa/issues/301 and hopefully this can be addressed soon.

@Bramleyl
why do you use once(random()) not just random()?

@Grzesiek2010 the once function means essentially “only evaluate the arguments if the node’s value is null”. This is important when using functions like random or now because otherwise they will be constantly re-evaluated up through form saving.

The behavior of random on its own currently matches what once(random()) should do but that is a bug and should not be relied on.

Ahh ok got it, thanks.

1 Like

In 1.14.1 this problem stays!!! It's horrible!!! It's ruins everything! HELP!!!
Can someone quickly rollback once() to some previous state 1.13.?
Please!

@AndrewA if you have an idea on how to address it, please send in a pull request!

1 Like

@AndrewA Alternatively, if you don't have an idea on how to fix it, you can always download previous versions of Collect at https://github.com/opendatakit/collect/releases.

Thank you very much for the detailed issue report, @Bramleyl. This was a tricky issue to identify and your report was very helpful. The problem has now been fixed thanks to @dcbriccetti and is released in ODK 1.14.2.

New forms will immediately work as expected. For forms that were first opened in versions 1.14.0 or 1.14.1, you will need to clear the form cache for the fix to come into effect. Tap on the three dots at the top right of the landing page and then go to admin settings. From "Reset application...", select ONLY "Form load cache (.cache folder)" and tap reset. Resetting the form cache is always a safe operation, it just means the form may take a little bit longer to open next time it is loaded.

Forms that were first opened in versions less than 1.14.0 should have continued working as expected.

2 Likes

Thanks very much @LN and @dcbriccetti for the fix! Will update our forms accordingly.

A post was split to a new topic: How to display 40 random numbers on one screen