/** * 随机数发生器 */ 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;
// 产生随机数 private long rand ( long r ) { // a,c,m为常数 r = ( r * a + c ) % m;//Xn+1=(aXn + c)mod m return r; }
/** * 表示a~b之间的一个随机数 * * @param a * @param b * @param rand * @return */ private long little ( int a, int b, long rand ) { return a + rand % ( 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); } }