Math类 Random类

java.lang.Math    

一堆的数学方法

    * public static int abs(int a)
    * public static double ceil(double a)
    * public static double floor(double a)
    * public static int max(int a,int b) min自学
    * public static double pow(double a,double b)   //a的b次方
    * public static double random()
    * public static int round(float a)    四舍五入 参数为double的自学
    * public static double sqrt(double a)          平方根
*/

Math.random()   :  返回大于等于 0.0 且小于 1.0 的伪随机 double 值。

Random类

   Random r = new Random();

   int x  = r.nextInt()  ;               //  生成一个随机数

      int y = r.nextInt(100)  ;       //  随机生成0到99的一个其中一个   

     Math.random()   使用起来比较方便

/*
* A:Random类的概述
    * 此类用于产生随机数如果用相同的种子创建两个 Random 实例,
    * 则对每个实例进行相同的方法调用序列,它们将生成并返回相同的数字序列。
* B:构造方法
    * public Random()
    * public Random(long seed)   //  使用种子来生成随机数
* C:成员方法
    * public int nextInt()
    * public int nextInt(int n)(重点掌握)
*/

猜你喜欢

转载自www.cnblogs.com/yaobiluo/p/11302113.html