Using Javascript's Math.random in AE Scripting Code || Not so random?
Hey Friends,
I'm practicing how to create elements really quickly via scripting.
I'm using Javascript's Math.random.
However, I'm getting the impression that it's not very random.
Here's my code.
{
app.beginUndoGroup("My Code");
var numObj=100;
var myComp = app.project.activeItem;
var mySolid = myComp.layers.addSolid([1,1,1], "my square", 1920, 1080, 1);
mySolid.moveToEnd();
var brandcolors=[[191,191,191],[242,230,219],[89,71,55],[144,199,186],[219,242,230]];
var easeIn = new KeyframeEase(0.5, 50);
var easeOut = new KeyframeEase(0.75, 85);
var Exp="";
//for (u = 0; u<numObj; u++)
//{
// var myRandom= ((1920-0)*Math.random())+0;
// alert(Math.round(myRandom));
// }
for (m = 0; m<numObj; m++)
{
var compBG = brandcolors[m%brandcolors.length]/255;// comp background color
var myX= Math.round(((1920-0)*Math.random())+0);
var myY= Math.round(((1080-0)*Math.random())+0);
//alert("I start out "+myX);
var myCirclesize=((200-20)*Math.random())+20;
var randomStrokeWidth= ((30-10)*Math.random())+10;
var myShape= myComp.layers.addShape();
myShape.moveToBeginning();
myShape.name="tomi"+m+"name";
var myPosition = myShape.property("position");
//alert("I end up "+myX);
myPosition.setValue([myX,myY]);
myPosition.expression=Exp;
//ELIPSE SIZE
var shapeGroup = myShape.property("Contents").addProperty("ADBE Vector Group");
var Ellipse = shapeGroup.property("Contents").addProperty("ADBE Vector Shape - Ellipse");
Ellipse.property("ADBE Vector Ellipse Size").setValue([myCirclesize,myCirclesize]);
//STROKE COLOR
var EllipseStroke = shapeGroup.property("Contents").addProperty("ADBE Vector Graphic - Stroke");
EllipseStroke.property("ADBE Vector Stroke Color").setValue(compBG);
//STROKE SIZE
EllipseStroke.property("ADBE Vector Stroke Width").setValue(randomStrokeWidth);
//STROKE TYPE
EllipseStroke.property("ADBE Vector Stroke Line Cap").setValue(2);
//TRIM PATHS
var randomStartTime=((1-1)*Math.random())+1;
var randomDur=((1-.6)*Math.random())+.6;
var myTrim = myShape.property("Contents").addProperty("ADBE Vector Filter - Trim");
myTrim.property("ADBE Vector Trim End").setValuesAtTimes([randomStartTime,randomStartTime+randomDur],[0,100]);
myTrim.property("ADBE Vector Trim Start").setValuesAtTimes([randomStartTime+.2,.2+randomStartTime+randomDur],[0,100]);
myTrim.property("ADBE Vector Trim Offset").setValuesAtTimes([randomStartTime,randomStartTime+randomDur],[0,90]);
//SETTING EASE ON TRIM PROPERTY
myTrim.property("ADBE Vector Trim End").setTemporalEaseAtKey(1, [easeIn], [easeOut]);
myTrim.property("ADBE Vector Trim Start").setTemporalEaseAtKey(2, [easeIn], [easeOut]);
myTrim.property("ADBE Vector Trim Offset").setTemporalEaseAtKey(1, [easeIn], [easeOut]);
myTrim.property("ADBE Vector Trim Offset").setTemporalEaseAtKey(2, [easeIn], [easeOut]);
// alert("And I'm still "+myX);
}
app.endUndoGroup();
}
When I tell it to alert me of the numbers it's generating, the values I get are more random. When I comment out my alert, I get several repeats of the same values.
Any ideas on what's going on?
Thanks in advance!
Best,
Tomi
