作者tinlans ( )
看板Programming
标题Re: [问题] 请问有C++现成的uniform函式吗?
时间Thu Feb 26 21:04:36 2009
※ 引述《lty721231 (TY)》之铭言:
: 我需要别人写好的uniform分布的函式
: 我之前有用过lcgrand.h 和 lcgrand.c
: 但是我後来做数值统计发现并没有符合uniform的分布
: 我也不想用srand time null
: 所以我想请问大家是否有使用过某些好用的函式库
: 并请问要到哪里下载呢?
: 谢谢!
: 我用的是 Visual C++ 2005
可以用 C++ TR1 或 Boost 提供的 random lib,
你想要 uniform 还是 normal distribution 的乱数都有办法生出来,
但是 call srand 设定一个 seed 还是必要的。
C++ TR1 文件:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf
Boost.random 文件:
http://www.boost.org/doc/libs/1_38_0/libs/random/index.html
我只知道最新的 VC++ 是有 TR1 函式库的支援,
不知道 2005 的 service pack 有没有,
没有的话可以装个 boost 来用。
其实 C 的 rand() 提供的就是 uniform dist. 乱数了,
但是你把它的结果做 % 运算可能破坏这个性质。
--
Ling-hua Tseng (
[email protected])
Department of Computer Science, National Tsing-Hua University
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Software pipelining for VLIW architectures
Homepage:
https://www.tinlans.org
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.160.111.131
1F:→ lty721231:谢罗 我试试看140.116.215.227 02/27 12:37