title: How to obtain a value based on a certain probability
body: <p>I have some functions which generate double, float, short, long random values. I have another function to which I pass the datatype and which should return a random value. Now I need to choose in that function the return value based on the passed datatype. For example, if I pass float, I need:</p>
  
  <p>the probability that the return is a float is 70%, the probability that the return is a double, short or long is 10% each. I can make calls to the other function for generating the corresponding random values, but how do I fit in the probabilistic weights for the final return? My code is in C++.</p>
  
  <p>Some pointers are appreciated. </p>
  
  <p>Thanks.</p>