# The randomization algorithm in Castor

Castor uses a validated variable block randomization model. This randomization algorithm is constructed in such a way that randomized inclusions are divided across groups (with optional stratification) in variable block sizes. This is done to ensure true randomness during the allocation.

You can define your groups and choose the block sizes in the study settings. The provided selection of block sizes is dependent on the number of groups and their assigned weight. Various factors influence the selection of block sizes, such as the number of inclusions and strata in the study. We recommend consulting a statistician to ensure you are selecting the right block sizes, as this cannot be changed once you've started randomizing.

Example: In a study there are two randomization groups (A and B), with the weight 1:1. If you select the block sizes 4, 6 and 8, there will be three different possible blocks generated in your study: AABB, AAABBB, and AAAABBBB. A block is generated with the first randomization and thereafter as soon as a previous block is used up. At every block generation moment, one of the three block sizes will be randomly selected. When a record is randomized, the allocation will be randomly selected from the current block in use. Thus, as records are randomized in a study, various blocks are created and used up, but at every moment there will be one block in use, provided there is no stratification.

Stratification influences the block generation in the sense that there are different blocks created for the different strata. If one stratification factor is used, there will be different blocks for each stratum at any given moment. If we take gender as an example stratification factor with two possible strata (male, female), there will be two blocks in use at any given moment, one of which will be used for randomization of males  and the other for females. If more than one stratification factor is used, there will be a different block generated for each combination of strata. The generation of blocks and allocation is otherwise the same as described above.

As inclusions are divided among different block sizes, it may initially appear that the division is unequal, but eventually the distribution will be more or less balanced, provided that you have selected reasonable blocks based on your study . An exact 1:1 balance is only possible if all created blocks are used up at the end of data collection. This is unlikely, therefore a slight imbalance should be expected.