9.24 hands-on brain

Consider the following code, you find what is special about it?

 

 This code defines overloaded functions, so the two function names inside the same output, but the results are not the same as running.

 

Write a method, using the above algorithm to generate a random integer to specify the number (such as 1000) of.

 

 

Modulus = 231-1 = int.MaxValue Multiplier = 75 = 16807 C = 0 when the number of displayed through 231-2, it may be repeated.

public class suiji
{
private static final int N = 200;
private static final int LEFT = 40;
private static final int RIGHT = 10000;
private static long x0 = 1L;
private long a = 1103515245L;
private long c = 12345L;
private long m = 2147483648L;

// generates a random number
Private Long RAND (R & lt Long)
{
// A, C, m is a constant
R & lt = (R & lt * A + C)% m; @. 1 = Xn + (C + AXN) m MOD
return R & lt;
}

A ~ * represents a random number between B
Private Long Little (A int, int B, Long RAND)
{
return RAND% A + (B - A +. 1);
}

private void recursion ( int count, long rand )
{
if (count >= N)
{
return;
}
rand = rand (rand);
long r = little (LEFT, RIGHT, rand);
System.out.print (r + " ");
recursion (++count, rand);
}

public static void main ( String[] args )
{
suiji recur = new suiji ();
recur.recursion (0, x0);
}
}

 

Guess you like

Origin www.cnblogs.com/2940500426yingxin/p/11604624.html