prefix [ n - 1 ] is sum of all frequencies . Generate a random number with value from 1 to this sum
Random rand = new Random ( ) ; int r = ( ( int ) ( rand . Next ( ) * ( 323567 ) ) % prefix [ n - 1 ] ) + 1 ;