Write a method that uses the above algorithm to generate a random integer of a specified number (for example, 1000).

Source: Internet
Author: User

Write a method that uses the above algorithm to generate a random integer of a specified number (for example, three).

 //A,c,m is constant

R = (R * A + C)% m

Modulus=231-1=int. MaxValue

multiplier=75=16807

C=0

It is possible to repeat after the number of 231-2 has been displayed.

public class Suiji {

/**

* @param args

*/

public static void Main (string[] args) {

TODO auto-generated Method Stub

Long a=123;

Long c=321;

Long m=456;

for (int i=0;i<1000;i++)

System.out.println (rand (I, A, C, M));

}

public static long rand (long R,long a,long c,long m)

{

R = (R * A + C)% m;

return R;

}

}

Look at the following code, do you find anything special?

Methodoverload.java

Using Overloaded Methods

public class Methodoverload {

public static void Main (string[] args) {

System.out.println ("The square of the integer 7 is" + Square (7));

System.out.println ("\nthe square of double 7.5 is" + square (7.5));

}

public static int square (int x) {

return x * x;

}

public static double square (double y) {

return y * y;

}

}

I find that functions of the same name can be different, and different parameter types can automatically invoke the corresponding function (method), that is, the overload of the method.

Two or more methods that meet the following conditions 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 is not used as a criterion for method overloading.

Write a method that uses the above algorithm to generate a random integer of a specified number (for example, 1000).

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.