java高效实现随机数的方法

具体的介绍请看:http://javamex.com/tutorials/random_numbers/xorshift.shtml

具体的代码如下:

private static int randomIntFrom0to(int max) {
		// XORShift instead of Math.random
		// http://javamex.com/tutorials/random_numbers/xorshift.shtml
		long x = System.nanoTime();
		x ^= (x << 21);
		x ^= (x >>> 35);
		x ^= (x << 4);
		return Math.abs((int) x % max);
	}


你可能感兴趣的:(java技术分享)