## Random pixels in an oval (ellipse) shaped area

Hi,

I need to put a lot of random points inside some oval shaped area or, in other words, between the inner and outer limits of two ellipses.

You can test the following code I made and you'll understand what I need:

import flash.display.Bitmap;
import flash.display.BitmapData;

var white:uint = 0xFFFFFF;
var black:uint = 0x000000;

var dist:Number;
var posX:Number;
var posY:Number;
var angle:Number;

var myBitmapData:BitmapData = new BitmapData(800, 800, false, black);

function randomRange(minNum:Number, maxNum:Number):Number {
return ((Math.random() * (maxNum - minNum + 1)) + minNum);
}

return (nDegree * Math.PI/180);
}

if (nAngle >= 0 && nAngle <= 90) {
}

if (angle >= 90 && angle <= 180) {
}

if (angle >= 180 && angle <= 270) {
}

if (angle >= 270 && angle <= 360) {
}

}

function generatePoints(innerLimit:Number, outerLimit:Number, nbStars:Number):void {
var i:uint = 0;
var oldDist:Number = 0;

while (i < nbStars) {
dist = randomRange(innerLimit, outerLimit);
oldDist = dist;
angle = Math.random() * 360;

// Convert polar to cartesian

myBitmapData.setPixel(Math.round(posX)+400, Math.round(posY)+400, white);

i = i + 1
}
}

generatePoints(250, 300, 25000);

var myBitmapImage:Bitmap = new Bitmap(myBitmapData);

Test it with a stage of at least 800x800 pixels.

My problem with this code is that there are deformities at each 90 degrees and I've never been able to eliminate these.

I'm sure there's a better way to do what I want but I just didn't succeed at finding it.

Any help would be appreciated.

Thanks.

PS: If you have a fast computer you can change the 3rd parameter in the line "generatePoints(250, 300, 25000);" to 100000 (or even more) and the deformities will get clearer.