text: Write a function that generates one of 3 numbers according to given probabilities | This function generates ' x ' with probability px / 100 , ' y ' with probability py / 100 and ' z ' with probability pz / 100 : Assumption : px + py + pz = 100 where px , py and pz lie between 0 to 100 ; Generate a number from 1 to 100 ; r is smaller than px with probability px / 100 ; r is greater than px and smaller than or equal to px + py with probability py / 100 ; r is greater than px + py and smaller than or equal to 100 with probability pz / 100
code: int random ( int x , int y , int z , int px , int py , int pz ) { int r = rand ( 1 , 100 ) ; if ( r <= px ) return x ; if ( r <= ( px + py ) ) return y ; else return z ; }