生成random随机数,OF中该怎样实现?
-
- 列表
-
若想得到服从高斯分布的随机数,应该怎样修改?
-
Foam::scalar Foam::Random::scalar01() { return osRandomDouble(); }
->
OSspecific/POSIX/POSIX.C
Foam::scalar Foam::osRandomDouble() { #ifdef USE_RANDOM return (scalar)random()/INT_MAX; #else return drand48(); #endif }
->
http://www.cplusplus.com/forum/beginner/39274/
http://blog.csdn.net/langeldep/article/details/7192906
具体的对于C++随机数这个东西我没有太细研究过,只能随便找找,你看看有没有帮助。
-
刚刚运行了一下代码,发现 seed 给定之后,重复运行代码,得到的随机数永远是相同的。
正如CFD-Online 的这篇帖子(#12)所说:A random number generator generates a "pseudo"-random number from the previous number. The number you give to the constructor is the start of the sequence (the predescessor of your first random number)另外 Random 的构造函数中的 seed 是有限制的:
Foam::Random::Random(const label seed) { if (seed > 1) { Seed = seed; } else { Seed = 1; } osRandomSeed(Seed); }
-
随便找了找 http://www.cplusplus.com/reference/cstdlib/rand/
This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using function srand.
你试试纯C++吧