生成加权随机数
public function weightedRandom( Struct options ) { var tempArr = []; for( var o in arguments.options ) { var weight = arguments.options[ o ] * 10; for ( var i = 1; i<= weight; i++ ) { arrayAppend( tempArr, o ); } } return tempArr[ randRange( 1, arrayLen( tempArr ) ) ];}// test itopts = { 0=.8, 1=.1, 2=.1 };for( x = 1; x<=10; x++ ){ writeDump( weightedRandom( opts ) ); }
德玛西亚99
相关分类