I'm sorry, I can not directly answer your question. I donβt remember the cycle time of the Java random number generator. Although I really think you are cutting it with the number of numbers you generate.
But what I learned in my computer engineering statistics classes may help you.
I learned that the best way to generate the most random numbers is to use the Mersen Twister random number generator. This generator will provide you with enough random numbers that will not need to be reordered, it has a period (2 ^ 19937) - 1
Here is the source code for MerseeneTwister
https://java2s.com/Open-Source/Java/Natural-Language-Processing/MorphAdorner/edu/northwestern/at/utils/math/randomnumbers/MersenneTwister.java.htm
Here is a class to generate your random numbers.
class RandomVariable { private static MersenneTwister rnd = new MersenneTwister(); public static double rand() { return rnd.nextDouble(); } public static double uniform(double min, double max) { return min + (max - min) * rand(); } }
Here is a sample for generating a random number. Please note that I removed the comments from the source. This may affect the nature of the open source code, but I could not completely copy and create it as code.
import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class sample{ public static void main(String args[]){ RandomVariable gen = new RandomVariable(); double num = gen.uniform(-1,1); int n = 10000; Set<Double> nums = new HashSet<Double>(); while (numbers.size() < n) nums.add(gen.uniform(-1,1)); } } class RandomVariable { private static MersenneTwister rnd = new MersenneTwister(); public static double rand() { return rnd.nextDouble(); } public static double uniform(double min, double max) { return min + (max - min) * rand(); } } class MersenneTwister extends java.util.Random implements Serializable {
Dan Ciborowski - MSFT
source share