LCG vs Math.random()
forked from forked from: random_LCG (diff: 31)
ActionScript3 source code
/**
* Copyright greentec ( http://wonderfl.net/user/greentec )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9Meh
*/
// forked from makc3d's forked from: random_LCG
// forked from greentec's random_LCG
package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.events.Event;
import com.bit101.components.Label;
import flash.geom.Matrix;
public class FlashTest extends Sprite {
public var screenBitmap_container:Bitmap;
public var screenBitmap:BitmapData;
public var overBitmap:BitmapData;
public static var num:Number = 31415926;
public var pointNum:uint=0;
public var _label:Label;
public var _label2:Label;
public var _label3:Label;
public function FlashTest() {
// write as3 code here..
//Style.setStyle(Style.DARK);
_label = new Label(this, 10, 10, "");
//_label.color = 0xffffff;
_label2 = new Label(this, 10, 100, "LCG");
_label3 = new Label(this, 10, 235, "Math.random()");
screenBitmap = new BitmapData(265, 265, true, 0x20ff0000);
screenBitmap_container = new Bitmap(screenBitmap);
screenBitmap_container.x = 100;
screenBitmap_container.y = 100;
addChild(screenBitmap_container);
overBitmap = new BitmapData(265, 265, true, 0x00000000);
addEventListener(Event.ENTER_FRAME, onLoop);
}
public function onLoop(e:Event):void
{
if(pointNum<150000)
{
overBitmap.lock();
screenBitmap.lock();
for(var i:int=0;i<500;i+=1)
{
//screenBitmap.setPixel32(random()*465, random()*465, 0x11000000);
//screenBitmap.setPixel32(Math.random()*465, Math.random()*465, 0x80ffffff);
overBitmap.setPixel32(random()*265, random()*130, 0x10000000);
overBitmap.setPixel32(Math.random()*265, Math.random()*130 + 135, 0x10000000);
pointNum += 1;
_label.text = "iteration : " + String(pointNum);
//_label2.text = String(random());
}
screenBitmap.draw(overBitmap, new Matrix(), null, BlendMode.HARDLIGHT);
screenBitmap.unlock();
overBitmap.unlock();
}
else
{
removeEventListener(Event.ENTER_FRAME, onLoop);
}
}
public static function random():Number
{
num = (num * 1664625 + 1013904223) % 0x100000000;
return num / 0x100000000;
}
}
}
