Skip to content
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(不使用皮肤)
  • 不使用皮肤
折叠
CFD中文网

CFD中文网

  1. CFD中文网
  2. OpenFOAM
  3. 生成random随机数,OF中该怎样实现?

生成random随机数,OF中该怎样实现?

已定时 已固定 已锁定 已移动 OpenFOAM
11 帖子 4 发布者 11.5k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    写于 最后由 编辑
    #2

    https://coding.net/u/dyfluid/p/Solvers_DYFLUID/git/tree/master/randomNumber

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    1 条回复 最后回复
  • Y 离线
    Y 离线
    yuanlee2011
    写于 最后由 编辑
    #3

    若想得到服从高斯分布的随机数,应该怎样修改?

    1 条回复 最后回复
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    写于 最后由 编辑
    #4

    已更新,

    https://coding.net/u/dyfluid/p/Solvers_DYFLUID/git/blob/master/randomNumber/randomNumber.C

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    Y 2 条回复 最后回复
  • Y 离线
    Y 离线
    yuanlee2011
    在 中回复了 李东岳 最后由 编辑
    #5

    @李东岳 谢谢!

    1 条回复 最后回复
  • Y 离线
    Y 离线
    yuanlee2011
    在 中回复了 李东岳 最后由 编辑
    #6

    @李东岳 发现不同的seed值对应一系列不同的随机数(组),请问seed有什么意义?赋值时应注意哪些问题?

    1 条回复 最后回复
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    写于 最后由 编辑
    #7
    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++随机数这个东西我没有太细研究过,只能随便找找,你看看有没有帮助。

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    1 条回复 最后回复
  • 浪 离线
    浪 离线
    浪迹天大
    写于 最后由 编辑
    #8

    刚刚运行了一下代码,发现 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);
    }

    OpenFOAM 学习交流:https://openfoam.top

    1 条回复 最后回复
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    写于 最后由 编辑
    #9

    随便找了找 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++吧 :mihu:

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    星 1 条回复 最后回复
  • 星 离线
    星 离线
    星星星星晴
    在 中回复了 李东岳 最后由 编辑
    #10

    @东岳 顺手请问一下如何生成随机向量,其模为1

    游荡

    星 1 条回复 最后回复
  • 星 离线
    星 离线
    星星星星晴
    在 中回复了 星星星星晴 最后由 编辑
    #11

    @星星星星晴 傻了 知道了

    游荡

    1 条回复 最后回复

  • 登录

  • 登录或注册以进行搜索。
  • 第一个帖子
    最后一个帖子
0
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]