Method of the hands of the brain

Source: Internet
Author: User

Hands-on brain:

(1) Pure random number generator

Modulus=231-1=int. MaxValue

multiplier=75=16807

C=0

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

Hands-on brain:

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

The code is as follows:

Package Suijishu;

Public class Suijishu {

Public Long a=12345l;//defines the a,b,c variable of type long

Public long c=12345l;

Public long m=456123l;

Public long r=1;

Public Long rand ()//Call the function of the pure random number generator

{

R= (r*a+c)%m;

return R;

}

Public Static void Main (string[] args) {

TODO auto-generated Method stub

Suijishu s=New Suijishu ();

long R;

for (int i=1;i<1000;)//output 1000 random numbers

{

R=s.rand ();

System. out. Print (r+ "");

i++;

if (i%20==0)//Enter 20 line breaks per input

System. out. println ("");

}

}

}

Code:

(2)

Take a look at the following code, do you find anything special?

Code to run:

The difference between integral and floating-point squares is found, and the floating-point type can be accurate to decimal digits.

Method of the hands of the brain

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.