flash on 2010-10-25

by enecre
♥0 | Line 32 | Modified 2010-10-25 21:39:37 | MIT License
play

ActionScript3 source code

/**
 * Copyright enecre ( http://wonderfl.net/user/enecre )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/Ahp1
 */

package {
    import flash.text.TextField;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private var tf:TextField = new TextField();
        
        public function FlashTest() {
            // write as3 code here..
            var numSimulate:int = 10000;
            var numTyusen:int = 1145;
            var uraritsu_true:Number = 31.71;
            var uraritsu_yakuza:Number = 31.26;
            
            tf.width = tf.height = 465;
            addChild(tf);
            
            var kentei:int = 0;
            
            var rand:Function = Math.random;
            
            for(var i:int = 0; i < numSimulate; i++){
                var ura:int = 0;
                for(var j:int = 0; j < numTyusen; j++){
                    if(rand() * 100 < uraritsu_true)ura++;
                }
                if(ura * 100 / numTyusen < uraritsu_yakuza)kentei++;
            }
            tr(keta2(kentei * 100 / numSimulate) + " %");
        }
        
        private function keta2(v:Number):Number{
            return int(v * 100) / 100;
        }

        
        private function tr(...o):void{
            tf.appendText(o + "\n");
            tf.scrollV = tf.maxScrollV;
        }

    }
}