Navigation

    CFD中文网

    CFD中文网

    • Login
    • Search
    • 最新

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

    OpenFOAM
    4
    11
    4925
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      yuanlee2011 last edited by

      • 列表
      1 Reply Last reply Reply Quote
      • 李东岳
        李东岳 管理员 last edited by

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

        线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
        CFD高性能服务器 http://dyfluid.com/servers.html

        1 Reply Last reply Reply Quote
        • Y
          yuanlee2011 last edited by

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

          1 Reply Last reply Reply Quote
          • 李东岳
            李东岳 管理员 last edited by

            已更新,

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

            线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
            CFD高性能服务器 http://dyfluid.com/servers.html

            Y 2 Replies Last reply Reply Quote
            • Y
              yuanlee2011 @李东岳 last edited by

              @李东岳 谢谢!

              1 Reply Last reply Reply Quote
              • Y
                yuanlee2011 @李东岳 last edited by

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

                1 Reply Last reply Reply Quote
                • 李东岳
                  李东岳 管理员 last edited by

                  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++随机数这个东西我没有太细研究过,只能随便找找,你看看有没有帮助。

                  线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                  CFD高性能服务器 http://dyfluid.com/servers.html

                  1 Reply Last reply Reply Quote
                  • 浪
                    浪迹天大 last edited by

                    刚刚运行了一下代码,发现 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 Reply Last reply Reply Quote
                    • 李东岳
                      李东岳 管理员 last edited by

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

                      线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                      CFD高性能服务器 http://dyfluid.com/servers.html

                      星 1 Reply Last reply Reply Quote
                      • 星
                        星星星星晴 @李东岳 last edited by

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

                        在写博士毕业论文,寻找postdoc或者职位中~
                        m.sui20@foxmail.com

                        星 1 Reply Last reply Reply Quote
                        • 星
                          星星星星晴 @星星星星晴 last edited by

                          @星星星星晴 傻了 知道了

                          在写博士毕业论文,寻找postdoc或者职位中~
                          m.sui20@foxmail.com

                          1 Reply Last reply Reply Quote
                          • First post
                            Last post

                          CFD中文网 | 东岳流体 | 京ICP备15017992号-2
                          论坛登录问题反馈可联系 li.dy@dyfluid.com