All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.bloodshura.ignitium.ntv.math.UnixRandom Maven / Gradle / Ivy

The newest version!
package com.github.bloodshura.ignitium.ntv.math;

import com.github.bloodshura.ignitium.math.random.XRandom;
import com.github.bloodshura.ignitium.ntv.lib.Unix;

/*
 * Although we could simply use CommonRandom, it's better to use 'srand48' and 'mrand48' Unix alternatives because they act with the full range of integers.
 *
 * That is: C's 'rand' generates only POSITIVE integer values (ranging from 0..2^31), so that the MSB is always 0, and C's 'srand' takes the seed argument as an INT instead of a LONG INT.
 *
 * In counterpart, 'mrand48' generates SIGNED integer values (ranging from -2^31..2^31), fully using the MSB, and 'srand48' takes the seed argument as a LONG INT.
 */
public class UnixRandom extends XRandom {
	@Override
	protected int next(int bits) {
		Unix.srand48(getSeed());

		return (int) Unix.mrand48();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy