A bunch of things. First we work on getting a random number uniformly distributed in the interval [0,1]. Then we can use this PRNG (pseudo random number generator) to get whatever else we need may it be random integers or random real numbers (even complex numbers actually) in whatever range under whatever distribution we want. That part is easy. The first part is hard.
Depending on how many numbers you need (like are we talking about a total of 100 or billions upon billions?) and depending on what kind of quality are you looking for (is it just for a small simulation or a game or are you looking for good cryptographic strength?), there are a LOT of methods available. As the quality goes up they get harder to code (properly I mean) and slower. Is there a particular reason you want to write your own? Because there are plenty of good libraries already out there in every language which already have all the details worked out with pretty sophisticated and efficient/fast implementations which it would hard for me, you, or anyone else to beat. Here is a list of all the well known ones. You can look here and implement your own or once you find the one you like just google it plus your favorite language.
The second link here just talks a bit more about PRNGs and the last section also tells you how to go from the first step to the second step to get pseudo-random numbers with whatever distribution you want. Basically you take the distribution's probability density function, find its cumulative distribution function, take the CDF's inverse and then run a uniformly distributed random number through it. Depending on the specific distribution, this can get ugly. And for specific distribution (like Gaussian) there are other faster methods.
MATLAB has a bunch of different methods for uniform distribution and you can specify which one you want. And from what I remember they only have uniform and normal distributions built-in (rand and randn).