Math.random () Random Number

You can get a [0,1) by Math.random () double type random number;

int S = ( int ) (Math.random () * 50 ); // generates a random integer of 0 to 50
 int K = ( int ) (100- (Math.random () * 50 )); // generates a 50 to 100 random integer 
System.out.println (K);
System.out.println (S);

Note: Do not write "(int) Math.random () * 100" brackets must be included on otherwise the result is 0.

Guess you like

Origin www.cnblogs.com/cuizhufeng/p/11797584.html