Search code examples
javarandomsystemtimemersenne-twister

MersenneTwister random number generator


I have a list(with 100.000 data) and i want to choose 4000 of them using MersenneTwister. I also want to use current system time because i run 15 times the program and i need different number of times.

MersenneTwister mt = new MersenneTwister("current system function");
for(int i=0; i<4000; i++){
    list1.add(mt.nextDouble());
}

I think that i must write something like this but i dont know which current system function to use to take different numbers


Solution

  • Use the no-argument form of the constructor. Quoting the javadocs at Apache Commons, "The instance is initialized using the current time plus the system identity hash code of this instance as the seed." Thus each run will produce different results.