One
Full "handwritten code implementation" random number generation
Example: generating 20 random numbers in a range 0~1000
1 Packagegenerate random numbers;2 Public classSuiji {3 Private Static Final intN = 20;//number of random numbers generated4 Private Static Final intleft = 0;//generate a left range of random numbers5 Private Static Final intright = 1000;//generate the right range of random numbers6 Private Static Longx0 = 1L;7 Private LongA = 1234567890L;8 Private Longc = 12345L;9 Private Longm = 2345678912L; Ten //Generate random numbers One Private LongRAND (LongR) A { - //A,c,m is constant -R = (R * A + C)% m;//xn+1= (aXn + c) mod m the returnR; - } - Private LongLittle (intLintRLongRand) { - returnL + rand% (R-l + 1 ); + } - intJishu=1; + Private voidRecursion (intCountLongRand) { A if(Count >=N) { at return; - } -Rand =rand (RAND); - LongR =Little (left, right, Rand); -System.out.print (R + ""); -Recursion (+ +)count, Rand); in } - Public Static voidMain (string[] args) { toSuiji A =NewSuiji (); +A.recursion (0, x0); - } the}
Operation Result:
Two, method overloading
I found that functions of the same name can be overloaded to implement different types of operations.
Two or more methods that meet the following conditions can form an "overloaded" relationship:
(1) The method name is the same;
(2) The parameter types are different, the number of parameters is different, or the order of the parameter types is different.
Note: The return value of the method cannot be used as a criterion for method overloading.
Hands on the Brain (ii)