Java Math Math tools and random stochastic functions

Source: Internet
Author: User
Tags pow square root

The math class contains methods for performing basic mathematical operations, such as absolute values, logarithms, square roots, and trigonometric functions. It is a final class, which defines a number of constants and static
State method. Common methods are as follows:
public static double sqrt (double A)//square root
public static double Ceil (double A)//the first integer greater than a
public static double floor (double A)//the first integer that is smaller than a
public static Double pow (double a,double b)//index, base a, b exponent
Puiblic Static Long round (double A)//rounded
public Staic int round (float a)//rounding
public static double random ()//Generate 0~1

Java three ways to generate random numbers:
1. Use System.currenttimemillis () to get a long number with a current time-millisecond number
2. Returns a random double value of 0 to 1 via math.random ()
3. Generate a random number through the random class, which is a professional random tool class, powerful
The random algorithm implemented in the random class is pseudo-random, that is, random with rules. There is an Origin seed number (seed), the same seed as the random object, generated the same number of times
The same as the random number
Construction Method:
1.public Random ()
2.public Random (Long Seed)

Common methods
public void nextbytes (byte[] bytes)
public int Nextint ()
public int Nextint (5)//[0,5) is an integer that never takes 5
public int Nextboolean ()//Boolean
public int nextfloat ()//0-1 floating point number
public int nextdouble ()//0-1 double type floating-point number

The math class contains methods for performing basic mathematical operations, such as absolute values, logarithms, square roots, and trigonometric functions. It is a final class, which defines a number of constants and static
State method. Common methods are as follows:
public static double sqrt (double A)//square root
public static double Ceil (double A)//the first integer greater than a
public static double floor (double A)//the first integer that is smaller than a
public static Double pow (double a,double b)//index, base a, b exponent
Puiblic Static Long round (double A)//rounded
public Staic int round (float a)//rounding
public static double random ()//Generate 0~1

Java three ways to generate random numbers:
1. Use System.currenttimemillis () to get a long number with a current time-millisecond number
2. Returns a random double value of 0 to 1 via math.random ()
3. Generate a random number through the random class, which is a professional random tool class, powerful
The random algorithm implemented in the random class is pseudo-random, that is, random with rules. There is an Origin seed number (seed), the same seed as the random object, generated the same number of times
The same as the random number
Construction Method:
1.public Random ()
2.public Random (Long Seed)

Common methods
public void nextbytes (byte[] bytes)
public int Nextint ()
public int Nextint (5)//[0,5) is an integer that never takes 5
public int Nextboolean ()//Boolean
public int nextfloat ()//0-1 floating point number
public int nextdouble ()//0-1 double type floating-point number

ImportJava.util.Random; Public classMathrandomdemo { Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem.out.println (Math.floor (10.55));//the first integer smaller than itSystem.out.println (Math.ceil (10.55));//the first integer larger than itSystem.out.println (Math.pow (2,3));//3 times for index 2System.out.println (Math.Round (10.6));//RoundingSystem.out.println (MATH.SQRT (64));//the first integer smaller than itSystem.out.println (Math.random ()); Random random1=NewRandom ();                System.out.println (Random1.nextint ()); Random Random2=NewRandom (10);//The random number does not changeSystem.out.println (Random2.nextint ()); Random Random3=NewRandom (System.currenttimemillis ());//Sets the number to the number of milliseconds of time, which is changingSystem.out.println (Random3.nextint ()); System.out.println (Random3.nextint (5));//randomly generated [0,5], less than 5System.out.println (Random3.nextboolean ()); System.out.println (Random3.nextdouble ());//Double PrecisionSystem.out.println (Random3.nextfloat ());//Single Precision            }}

Java Math Math tools and random stochastic functions

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.