public class RandomCy {
private static final long multiplier = 0x5DEECE66DL;
private static final long addend = 0xBL;
private static final long mask = (1L << 48) - 1;
/**
* 默认的随机种子 是 -1
*/
private long seed = -1;
public RandomCy() {
seed = -1;
}
/**
* 设置随机种子
* @param seed
*/
public RandomCy(int seed) {
this.seed = seed;
}
/**
* 设置随机种子
* @param seed
*/
public void setSpeed(int seed)
{
this.seed = seed;
}
/**
* 获取lang 类型的随机数
* @return
*/
public long nextLong() {
return ((long) (next(32)) << 32) + next(32);
}
/**
* 获取int 类型的随机数
* @return
*/
public int nextInt() {
return next(32);
}
/**
* 运算
* @param step
* @return
*/
protected int next(int step) {
long nextSeed = 0;
seed = (seed * multiplier + addend) & mask;
nextSeed = seed;
return (int) (nextSeed >> (48 - step));
}
}
private static final long multiplier = 0x5DEECE66DL;
private static final long addend = 0xBL;
private static final long mask = (1L << 48) - 1;
/**
* 默认的随机种子 是 -1
*/
private long seed = -1;
public RandomCy() {
seed = -1;
}
/**
* 设置随机种子
* @param seed
*/
public RandomCy(int seed) {
this.seed = seed;
}
/**
* 设置随机种子
* @param seed
*/
public void setSpeed(int seed)
{
this.seed = seed;
}
/**
* 获取lang 类型的随机数
* @return
*/
public long nextLong() {
return ((long) (next(32)) << 32) + next(32);
}
/**
* 获取int 类型的随机数
* @return
*/
public int nextInt() {
return next(32);
}
/**
* 运算
* @param step
* @return
*/
protected int next(int step) {
long nextSeed = 0;
seed = (seed * multiplier + addend) & mask;
nextSeed = seed;
return (int) (nextSeed >> (48 - step));
}
}