# How do I generate Maxwell-Boltzmann variates using a uniform distribution random number generator?

I am doing a molecular dynamics simulation. I need to assign initial velocities to the atoms. I want to assign the initial velocities which follow the Maxwell-Boltzmann distribution. How do I calculate such initial velocities using a uniform random number generator with range [0,1)?

The initial velocities are drawn from a Gaussian distribution with variance $$\sigma_i^2=\frac{k_{\textrm{B}}T}{m_i},$$ where $k_{\textrm{B}}$ denotes Boltzmann's constant, $T$ is the temperature and $m_i$ is the mass of the $i^{\textrm{th}}$ particle.
Let's put everything together: every component of the velocity of the $i^{\textrm{th}}$ particle is computed via $$v_{i,\alpha}=\sqrt{\frac{k_{\textrm{B}}T}{m_i}}\,\mathcal{N}(0,1)\,,\quad\alpha\in\{x,y,z\}\,,$$ where $\mathcal{N}(0,1)$ is a gaussian random number with variance 1 and mean 0.
With this definition, each velocity component follows a gaussian distribution $$\pi(v_\alpha)\textrm{d}v_\alpha\propto\exp\left(-\frac{v_\alpha^2}{2\sigma^2}\right)\textrm{d}v_\alpha\,,$$ but when you write the distribution of the velocity vector in spherical coordinates and integrate the angular components, you obtain $$\pi(v)\textrm{d}v \propto v^2\exp\left(-\frac{v^2}{2\sigma^2}\right)\textrm{d}v\,,$$ which is the desired Maxwell-Boltzmann distribution.