Random Number of functions in flex: Random (), round (), Ceil (), floor ()

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.