[SOLVED] Is there a better way to do this?
Hi! I am trying to create a formula (well I have, but am unsure if it is very good) that will be used to create an random discrete distribution based on a given set of minimum and maximum range of values. These min/max values are then fed into a random number generator. This is what I have at the moment int minRange = 5; int maxRange = 15; std::array<double, 3> distribution; // stores probability values eg. 0.50, 0.35, 0.15 int FirstMaxRange = maxRange * distribution[0]; int SecondMinRange = FirstMaxRange + 1; int SecondMaxRange = FirstMaxRange + (FirstMaxRange * distribution[1]) + 1; int ThirdMinRange = SecondMaxRange + 1; int ThirdMaxRange = SecondMaxRange + (SecondMaxRange * distribution[2]) + 1; std::discrete_distribution<int> dist{ distribution[0], distribution[1], distribution[2] }; // select which min and max values based on probability switch (dist(gen)) { case 0: return returnUniform(minRange, FirstMaxRange); case 1: return returnUniform(SecondMinRange, SecondMaxRange); case 2: return returnUniform(ThirdMinRange, ThirdMaxRange); default: //error here! return 0; } Note: the values minRange, maxRange and Distribution are usually fed from another function. they are just here for example purposes I know I lose info on conversion from double to int, (thus the +1's) This for generating stats for an rpg and I need whole numbers to be returned to the random number generator function. I am far from a math person. So I figure there has to be a better way? Or will this do? Thanks! EDIT: For clarification: i am trying to remove the hard coded values from the returnDiscrete method of randomNum class on this code: https://code.sololearn.com/c4201jw6c207/#cpp