Java 版 (精华区)
Java的Random自己带了一个,doc里面有数学公式...
我再给你个简单的,更好的自己去找吧
protected static final float MAX_FLOAT = 1.0F - 1.192092896e-07F;
protected static final float FLOAT_SCALE = 1.0F / 2147483563.0F;
protected static final double MAX_DOUBLE = 1.0D - 1.192092896e-07F;
protected static final double DOUBLE_SCALE = 1.0D / 2147483563.0D;
private static final int A = 16807;
private static final int M = 2147483647;
private static final int Q = 127773;
private static final int R = 2836;
private static final int MASK = 123459876;
protected int seed = 0;//你可别把0作为种子阿
//最简单的....
public int nextValue()
{
seed ^= MASK; // prevent zero seed
int k = seed / Q;
seed = A * (seed - k * Q) - R * k;
if (seed < 0)
seed += M;
return seed;
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.140毫秒