weighted randomization I would like to randomize subjects in two groups so that the allocation ratio is 1:1.
Let's say the control group already has 5 subjects while the experimental group already has 7 subjects. Then, the next subject will be randomized to the experimental group with a probability of 5/12. What if the allocation ratio is 1:2 (twice as many subjects in the experimental group compared to the control group)? What should be the allocation probability to the experimental group in the above example?
 A: The book Randomization in Clinical Trials (2nd ed.) by William Rosenberger and John Lachin (2016, Wiley) explains several methods for randomization for balancing treatment assignments (chapter 3). In general, the employment of such randomization procedures is called restricted randomization. The goal is to have equal numbers (or the target allocation) of patients assigned to each treatment group.
A relatively simple procedure is the Biased Coin Randomization (BCD($p$)). It works like this (for equal allocation, i.e. 1:1)$^{[1]}$: Let $n_A$ and $n_B$ be the current number of subjects assigned to treatment $A$ and $B$, respectively. The probability of the next subject being assigned to treatment $A$ in the trials is:
$$
\begin{equation}
  \mathbb{P}(\text{treatment}\ A)=\left\{
  \begin{array}{@{}ll@{}}
    1 - p, & \text{if}\quad n_A > n_B \\
    0.5, & \text{if}\ n_A = n_B \\
    p, & \text{if}\ n_A < n_B
  \end{array}\right.
\end{equation}
$$
where $p$ represents the bias in the randomization "coin" ($0.5\leq p\leq 1$). Efron$^{[2]}$ suggested $p=2/3$ while Pocock$^{[3]}$ suggested $p=2/3$ for a relatively small trial and $p=3/5$ for larger trials (e.g. $>100$ patients). The probabiltiy of imbalance of size $j$ for the BCD($p$) design in terms of $r=p/(1-p)$ is:
$$
\begin{array}{ll}
\hline
\text{Even } N & \text{Odd } N \\
\hline
1 - 1/r\ (j = 0) & \dfrac{r^2 - 1}{r^{j+1}}\ (\text{odd } j, j\geq 1) \\
\dfrac{r^2 - 1}{r^{j+1}} \ (\text{even } j, j\geq 2)& \\
\hline
\end{array}
$$
An an example for $N = 100$ and $p=2/3$, the probability of an imbalance of $j=4$ or more is about $0.125$.
Unequal allocation ratios
This design can be extended for unequal allocation ratios. If the required allocation ($A:B$) is $k$, the probability of assigning the next subject to treatment $A$ is
$$
\begin{equation}
  \mathbb{P}(\text{treatment}\ A)=\left\{
  \begin{array}{@{}ll@{}}
    \dfrac{k}{k + 1} - p, & \text{if}\quad n_A > kn_B \\
    \dfrac{k}{k + 1}, & \text{if}\ n_A = kn_B \\
    \dfrac{k}{k + 1} + p, & \text{if}\ n_A < kn_B
  \end{array}\right.
\end{equation}
$$
with the restriction $0<p<(1 - \frac{k}{k+1})$ where $k>1$.
Here are two plots showing $n_A$ with $N=100$ and an allocation ratio of 3:1 ($k=3$), once with $p = 0.05$ and once with $p = 0.2$. The procedure was simulated 100 times and each line shows one randomization. The red line was set at $75$ which corresponds to the exact allocation ratio. Notice that with larger $p$, the imbalance control is stricter (the lines don't jump around as much).


There are many other possible procedures such as Mass weighted urns$^{[4]}$ or another modification of the biased coin design$^{[5]}$
References
$[1]$: M.D. Smith, Biased-Coin Randomization. Wiley StatsRef: Statistics Reference Online, 2014.
$[2]$: B. Efron, Forcing a sequential experiment to be balanced. Biometrika. 1971; 58: 403-417.
$[3]$: S.J. Pocock, Clinical Trials: A Practical Approach. New York: Wiley, 1983.
$[4]$: W. Zhao, Mass weighted urn design - A new randomization algorithm for unequal allocations. Contemp. Clin. Trials. 2015; 43: 209-216.
$[5]$: O.M. Kutznetsova & Y. Tymofyeyev, Preserving the allocation ratio at every allocation with biased coin randomization and minimization in studies with unequal allocation. Statist. Med. 2012; 31: 701-723.
