Is there a more efficent, possibly more mathematical and less algorithmic way of achieving a similar random number distribution to this?
unsigned int weighted_random_UINT()
{
float r2 = 1;
while(rand() % 4 != 0) // 3/4 chance
{
r2 *= fmod(
((float)rand()/RAND_MAX)+1, // random float between 1 and 2
(float)UINT_MAX
);
}
return (unsigned int)r2 - 1;
}
Below is a less safe but more easily readable version of the inside of the while.
r2 *= ((float)rand()/RAND_MAX)+1;
The distribution visualized:

Comparison between the smoother solution in the question (1st graph) and the faster solution in the best answer (2nd graph):
comparison http://with-logic.co.uk/a/graph.png
I think you don’t have to loop through it, but once is enough, like so:
The first part is a geometric distribution, and the last one is an uniform distribution.
And you want
(1+U(0,1))^G(3/4).It should be possible to find some faster way to find G(3/4) though.
Edit:
I found it on wikipedia:
http://en.wikipedia.org/wiki/Geometric_distribution#Related_distributions
Thus you want:
Which should be just two calls to rand.