   Help with rand() custom range limit
  I am not good at math so can some one explain this float f=(rand()%10000)*0.0001f;return (f*(max-min))+min;my question is why it have to *0.0001f but i know rand()%10000 is 0~9999. Min and max is define by user. Also why f*(max-min)+minI am doing the particle system so must use random number also it should be float type.   
  The first part is giving you a percent: a float value between 0 and .9999f. The second part is applying that percentage to the size of your range and then adding the minimum to it.Say your range is 5 - 10 and your float percent comes back at 0.5f -- you end up with 0.5f * 5 + 5 = 2.5f + 5 = 7.5f   ;  `f' is supposed to be a number between 0 and 1, uniformly distributed. If you compute `(max-min)*f+min' when `f' is 0, you get `min', and if you compute it when `f' is 1, you get `max'. For values of `f' in between 0 and 1, you'll get values between `min' and `max'.However, your code has a small problem: RAND_MAX could be as small as 32767, so in your code `f' could have values between 0 and 0.2767 a lot more often than it should. You should probably compute `f' like this:const float scale_rand_down = 1.0f / RAND_MAX;float f = rand() * scale_rand_down;;  Did you try plugging in different values for '(rand % 10000)' (especially the endpoint values) into the rest of the formulas by hand? That kind of thing usually helps understand what's going on.   ;  Go with what alvaro posted, it's way better!   