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