java.util.Random
next方法的原理
比较好的参考文档:
http://isky001.iteye.com/blog/1339979
package random.utilrandom; import java.util.Random; public class TestRandom {
public static void main(String[] args) {
Random ran1 = new Random(10);
System.out.println("使用种子为10的Random对象生成[0,10)内随机整数序列: ");
for (int i = 0; i < 10; i++) {
System.out.print(ran1.nextInt(10) + " ");
}
System.out.println();
Random ran2 = new Random(10);
System.out.println("使用另一个种子为10的Random对象生成[0,10)内随机整数序列: ");
for (int i = 0; i < 10; i++) {
System.out.print(ran2.nextInt(10) + " ");
}
Random ran3 = new Random(10);
System.out.println("使用另一个种子为10的Random对象生成[0,10)内随机整数序列: ");
for (int i = 0; i < 10; i++) {
System.out.println(ran3.nextInt());
}
System.out.println();
Random ran4 = new Random(10);
System.out.println("使用另一个种子为10的Random对象生成[0,10)内随机整数序列: ");
for (int i = 0; i < 10; i++) {
System.out.println(ran4.nextInt());
}
}
}
Math.random()本质上是调用RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble();即是java.util.Random.nextDouble()
还有一个讲解线性同余公式的文章很不错
http://www.cnblogs.com/xkfz007/archive/2012/03/27/2420154.html
再来一个英文文档解释nextseed = (oldseed * multiplier + addend) & mask;