Hands on the Brain (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.