📜  在 Java 代码示例中使用 Math.random 生成随机数

📅  最后修改于: 2022-03-11 14:52:14.793000             🧑  作者: Mango

代码示例2
class GenerateRandom {
    public static void main( String args[] ) {
      int min = 50;
      int max = 100;
        
      //Generate random int value from 50 to 100 
      System.out.println("Random value in int from "+min+" to "+max+ ":");
      int random_int = (int)Math.floor(Math.random()*(max-min+1)+min);
      System.out.println(random_int);
    }
}