In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

ゲーム用 乱数生成(ActionScriptでXorshift)

Get Adobe Flash player
by karinharp 05 Apr 2010
package {
    import flash.display.*;   
    import flash.text.*;
	import flash.utils.*;    
	import flash.events.*;    
	
    public class FlashTest extends Sprite {
    	
    		private var i_s:Vector.<uint>;        
		private var tf:TextField;
   		private var ticker:Timer;
    			
        public function FlashTest():void {
			boot();			
			return;        
        }
        
        private function update(ev:TimerEvent):void{tf.text = String(this.xor128);return;	}   
   		private function boot():void { init(); this.graphics.beginFill(0x000000, 1); this.graphics.drawRect(0,0,360, 480); this.graphics.endFill();			tf = new TextField(); tf.width=480; tf.textColor = 0xFFFFFF; ticker = new Timer(100); ticker.addEventListener(TimerEvent.TIMER, update);ticker.start();addChild(tf); }     
    		private function init(a_seed:Vector.<uint> = null):void {
 	       	if(a_seed != null){ i_s = a_seed; }
 	       	else{ i_s = new Vector.<uint>(4, false); i_s[0]=Math.floor(Math.random()*uint.MAX_VALUE);i_s[1]=Math.floor(Math.random()*uint.MAX_VALUE);i_s[2]=Math.floor(Math.random()*uint.MAX_VALUE);i_s[3]=Math.floor(Math.random()*uint.MAX_VALUE);}
    		}
    		private function get seed():Vector.<uint> { return i_s; }
    		private function get xor128():Number { return (_xor128()/int.MAX_VALUE); }
    		private function _xor128():uint{ var t:uint; t=(i_s[0]^(i_s[0]<<11)); i_s[0]=i_s[1];i_s[1]=i_s[2];i_s[2]=i_s[3];return( i_s[3]=(i_s[3]^(i_s[3]>>19))^(t^(t>>8)));}
	}    
}