Java VS Matlab:Math.random()和rand [英] Java VS Matlab : Math.random() and rand

查看:87
本文介绍了Java VS Matlab:Math.random()和rand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下Java和Matlab中的随机数.

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

Java中的Math.random和Matlab中的rand具有相同的含义,或者两者是不同的吗?如果含义不同,有什么区别?

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

推荐答案

对于Matlab,请参考 http://www.mathworks.com/company/newsletters/news_notes/pdf/Cleve.pdf ,说明了乘法同余生成器在Matlab中的工作原理.

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.

对于Java,请参考 http://www.javamex.com/tutorials/random_numbers/java_util_random_algorithm.shtml#.VsMAw3WLSkA 解释了线性同余生成器如何在Java Utils类中用于随机数生成.

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.

在Matlab的MCG是LCG的特例的情况下,两者基本上是相同的算法,请参见此处: https://en.wikipedia.org/wiki/Linear_congruential_generator

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

是的,C ++(Borland),Java.Utils,Matlab语言使用的算法基本相同,因为它高效-内存效率极高,线性分布平坦(即伪随机)->但它由于序列相关性,它是质量较差的伪随机数.

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.

但是那里有更好的算法,不同的算法,例如Python,其PRNG使用Mersenne Twister算法,但是感知的结果随机性要低得多,请阅读以下内容:

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?

这篇关于Java VS Matlab:Math.random()和rand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆