Java VS Matlab : Math.random() and rand

Patrick

I want to ask about random number in Java and Matlab.

Math.random in Java and rand in Matlab has a same meaning or both is different? If different meaning, what the difference ?

GameOfThrows

For Matlab, refer to http://www.mathworks.com/company/newsletters/news_notes/pdf/Cleve.pdf which explains how the multiplicative congruential generator works in Matlab.

For Java, refer to http://www.javamex.com/tutorials/random_numbers/java_util_random_algorithm.shtml#.VsMAw3WLSkA which explain how the linear congruential generator works in the Java Utils class for random number generation.

Both are essentially the same algorithm where Matlab's MCG is a special case of LCG, see here: https://en.wikipedia.org/wiki/Linear_congruential_generator

And yes, C++ (Borland), Java.Utils, Matlab language uses essentially the same algorithm, because it is efficient - it is extremely memory efficient, it has a flat linear distribution (i.e. pseudo-random) -> but it is a poor quality pseudo-random, because of the serial correlation.

BUT there are better algorithms out there, and different ones, take Python for example, uses Mersenne Twister algorithm for its PRNG, but the perceived result is much less random, take a read at this: Random is barely random at all?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related