Randomization
Randomization in CommCare is a powerful feature that enables you to implement randomized workflows, generate random values, and tailor application logic based on random numbers. Below are a few ways that you can leverage randomization properties in CommCare.
Use the Random Function
You can ause the common Random Function (described here: CommCare Functions | random ) to randomize your outputs.
Return: Returns a random number between 0.0 (inclusive) and 1.0 (exclusive). For instance: 0.738
Arguments: None
Usage: random()
Example Usage: When you need to generate a random number. For example, to generate a number between 5 and 23, you can use (random()*(23 - 5)) + 5. This will be something like 12.43334. You can convert that to a whole number by using int((random()*(23 - 5)) + 5). You can also reference questions instead of directly typing numbers. Ex. int(random()*(/data/high_num - /data/low_num) + /data/low_num).
External Randomization
For projects requiring precise control over randomization, patient groups can be randomized externally and then uploaded to CommCare using the Case Importer tool (Importing Cases Using Excel) . This method is ideal when all participants are registered before randomization.
How to Implement External Randomization
Export Patient Data: After all participants are registered in CommCare, export their case data.
Randomize in Excel or External Tool: Use Excel or a dedicated randomization system to assign patients to groups (e.g., "Treatment" or "Control"). Ensure the assignments follow the required distribution.
Prepare for Import: Add the randomized group assignments to a column in the Excel file. Format the file according to CommCare's Case Importer guidelines, ensuring all required columns (e.g., Case ID) are included.
Upload to CommCare: Use the Case Importer tool in CommCare HQ to upload the updated case data with the group assignments.
Update Study Assignments: The uploaded group assignments will now be available as case properties in CommCare. These properties can be used to guide workflows or reporting.
Example Use Case: An implementing partner randomized patients externally using a statistical tool. During patient intake, when the patient was registered as a mobile worker, the study team entered the assigned study group into a custom user field in CommCare. This ensured that all participants followed the predefined group assignments during the study.
Additional Notes
This method is best suited for projects where all participants are registered upfront, as it ensures the correct distribution of participants across groups.
For projects with rolling admissions, consider alternative randomization approaches, such as using the
random()
function or bucketed randomization directly within CommCare.
Display a Random Question
You can set up a form that will display a random yes/no question from a lookup table. This is useful for asking randomized questions for doing knowledge assessment, or to send random behavior change communication out via messaging.
Read more here: Lookup Tables | Setup a Form to Display a Random Question from Lookup Table
Advanced Randomization Functions
For more advanced randomization functions, check out the CommCare Forum and search for other randomization questions.