export function generelizedRandomResponse ( x , ratingRange , epsilon = 0.9 ) { let p = Math . exp ( epsilon ) / ( Math . exp ( epsilon ) + ( ratingRange [ ratingRange . length - 1 ] - ratingRange [ 0 ] ) ) ; let q = 1 / ( Math . exp ( epsilon ) + ( ratingRange [ ratingRange . length - 1 ] - ratingRange [ 0 ] ) ) ; let probablities = [ ] ; for ( let i = ratingRange [ 0 ] ; i <= ratingRange [ ratingRange . length - 1 ] ; i ++ ) { if ( i == x ) probablities . push ( p ) ; else probablities . push ( q ) ; } let result = weightedChoice ( probablities ) ; return result ; } function weightedChoice ( p ) { let rnd = p . reduce ( ( a , b ) => a + b ) * Math . random ( ) ; return p . findIndex ( a => ( rnd -= a ) < 0 ) ; }