Take the random number of the specified range

xiaoxiao2021-03-06  51

Take the random number of the specified range

This is a very practical function. It is just to strengthen memory here, just remember that a formula is OK. Such as minimum min, maximum max, random number R ≤ Max in min ≤ r ≤ Max, formula is as follows: (int) ((Max - min 1) * Math.random ()) min I understand that there is nothing to say. The implementation code is as follows: / * * Create a date 2004-12-11 * * / / ** * Take the random number of specified range * * @Author wubai * * / public class getrandom {/ ** * Take the random number of specified range * * @Param min start range * @Param max End range * @return random number * / public int GETRANDOM (INT min, int max) {RETURN (INT) * Math.random ()) Min;} // Test public static void main (string [] args) {getrandom test = new getrandom (); int random = test.getrandom (10, 99); System.out.Println ("Random IS" Random }}

转载请注明原文地址:https://www.9cbs.com/read-81913.html

New Post(0)