The random function is very useful in flash. It can generate basic random numbers, create random moves, and random colors and other functions ., This tutorial explains how to make this example and how to use the random function to generate different results.
The basic random functions are as follows:
Math. Random ();
You can generate arbitrary decimal places between 0 and 1, such as 0.0105901374530933 or 0.872525005541986. There are several other functions that can be used to change the generated numbers, so that you can better use them in your video:
Math. Round ();
Math. Ceil ();
Math. Floor ();
These functions are used to obtain integers. Math. Round (); is used to obtain the nearest integer by rounding. Math. ceil (); is to obtain the nearest integer from the top, math. floor () and math. opposite to Ceil (), math. floor (); down to get the nearest integer
If you want to create a random number from X to Y, you can write
Math. Round (math. Random () * (Y-x) + X;
X and Y can be any number, even negative.
A key generated in the previous period
Sdatetimekey + = mx. Controls. datefield. datetostring (dnow, "yyyymmdd ");
Stemp = string (dnow. gethours ());
If (stemp. Length = 1)
Stemp = "0" + stemp;
Sdatetimekey + = stemp;
Stemp = string (dnow. getminutes ());
If (stemp. Length = 1)
Stemp = "0" + stemp;
Sdatetimekey + = stemp;
Stemp = string (dnow. getseconds ());
If (stemp. Length = 1)
Stemp = "0" + stemp;
Sdatetimekey + = stemp;
Stemp = string (dnow. getmilliseconds ());
If (stemp. Length = 1)
Stemp = "0" + stemp;
Sdatetimekey + = stemp;
Stemp = string (math. Round (math. Random () * (9999-1000) + 1000 );
Sdatetimekey + = stemp;