编写一个方法,使用以上算法生成指定数目(比 如1000个)的随机整数
import java.util.ArrayList; import java.util.List; public class RandomNumberGenerator { private static final long MULTIPLIER = 1664525; // 线性同余发生器的乘数 private static final long INCREMENT = 1013904223; // 线性同余发生器的增量 private static final long MODULUS = (long) Math.pow(2, 32); // 线性同余发生器的模值 public static List<Integer> generateRandomIntegers(int count) { List<Integer> randomIntegers = new ArrayList<>(); long seed = System.currentTimeMillis(); // 使用当前时间作为种子 for (int i = 0; i < count; i++) { seed = (MULTIPLIER * seed + INCREMENT) % MODULUS; randomIntegers.add((int) seed); } return randomIntegers; } public static void main(String[] args) { List<Integer> randomIntegers = generateRandomIntegers(1000); for (int num : randomIntegers) { System.out.println(num); } } }
参数和返回值类型不同,但函数名相同
标签:9.22,int,randomIntegers,List,long,seed,static From: https://www.cnblogs.com/zeyangshuaige/p/17722920.html