Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • 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

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Random Gaussian numbers

Random Gaussian numbers

Scheduled Pinned Locked Moved C / C++ / MFC
c++delphilounge
12 Posts 5 Posters 0 Views 1 Watching
  • 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.
  • C Chun Te Ewe

    Dear all, I was wondering if there is a way to generate random gaussian numbers with Visual C++. Borland Builder has the option randg to do just this. Many many thanks Chun Te

    R Offline
    R Offline
    Rickard Andersson20
    wrote on last edited by
    #2

    Chun Te, Ewe wrote: gaussin What is that? look up rand() in MSDN Library Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

    C 1 Reply Last reply
    0
    • R Rickard Andersson20

      Chun Te, Ewe wrote: gaussin What is that? look up rand() in MSDN Library Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

      C Offline
      C Offline
      Chun Te Ewe
      wrote on last edited by
      #3

      Sorry for the typo. The rand() just generates random numbers but not gaussian/normal distribution numbers. Chun Te

      R 1 Reply Last reply
      0
      • C Chun Te Ewe

        Sorry for the typo. The rand() just generates random numbers but not gaussian/normal distribution numbers. Chun Te

        R Offline
        R Offline
        Rickard Andersson20
        wrote on last edited by
        #4

        Chun Te, Ewe wrote: gaussian Sorry, but I don't know what a gaussian number is! :( Try go to www.msdn.microsoft.com and type in "gaussian" in the search field of "MSDN Library" and then see if you find something. Cheers! :) Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

        D 1 Reply Last reply
        0
        • C Chun Te Ewe

          Dear all, I was wondering if there is a way to generate random gaussian numbers with Visual C++. Borland Builder has the option randg to do just this. Many many thanks Chun Te

          D Offline
          D Offline
          Daniel Turini
          wrote on last edited by
          #5

          See This article[^] I see dumb people

          C 1 Reply Last reply
          0
          • C Chun Te Ewe

            Dear all, I was wondering if there is a way to generate random gaussian numbers with Visual C++. Borland Builder has the option randg to do just this. Many many thanks Chun Te

            J Offline
            J Offline
            jhwurmbach
            wrote on last edited by
            #6

            You did not even try to search CP for it, did you? Its here[^]for example. -- "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

            D 1 Reply Last reply
            0
            • R Rickard Andersson20

              Chun Te, Ewe wrote: gaussian Sorry, but I don't know what a gaussian number is! :( Try go to www.msdn.microsoft.com and type in "gaussian" in the search field of "MSDN Library" and then see if you find something. Cheers! :) Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

              D Offline
              D Offline
              Daniel Turini
              wrote on last edited by
              #7

              Rickard Andersson wrote: Sorry, but I don't know what a gaussian number is! It's not a gaussian number, it's a gaussian distribution. Let's pick a simple example: if you plot people's weight x #number of people with a specific weight, you'll get a gaussian distribution: most samples will concentrate on the middle of the graphic and less people on the borders. Gaussian distribution are also know as Normal distributions. It's know as the "bell curve" too. A picture worth more than a thousand words. See This article[^] I see dumb people

              1 Reply Last reply
              0
              • D Daniel Turini

                See This article[^] I see dumb people

                C Offline
                C Offline
                Chun Te Ewe
                wrote on last edited by
                #8

                Thanks...

                1 Reply Last reply
                0
                • J jhwurmbach

                  You did not even try to search CP for it, did you? Its here[^]for example. -- "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

                  D Offline
                  D Offline
                  Daniel Turini
                  wrote on last edited by
                  #9

                  Hehehe, I got you by a minute! I see dumb people

                  1 Reply Last reply
                  0
                  • C Chun Te Ewe

                    Dear all, I was wondering if there is a way to generate random gaussian numbers with Visual C++. Borland Builder has the option randg to do just this. Many many thanks Chun Te

                    C Offline
                    C Offline
                    Chun Te Ewe
                    wrote on last edited by
                    #10

                    I've found a mathematical formula to do this now. It assume zero mean and it is written in MatLab. sigma = 2; %The std deviation x1 = rand(1000,1); %Linear rand number between 0.0 to 1.0 x2 = rand(1000,1); z = sqrt(-2*sigma*log(x1)) * cos(2*pi*x2); the log here is ln, that is log to the base e. Now all we need is just to put it in C. Thanks to all who replied my post.

                    G 1 Reply Last reply
                    0
                    • C Chun Te Ewe

                      I've found a mathematical formula to do this now. It assume zero mean and it is written in MatLab. sigma = 2; %The std deviation x1 = rand(1000,1); %Linear rand number between 0.0 to 1.0 x2 = rand(1000,1); z = sqrt(-2*sigma*log(x1)) * cos(2*pi*x2); the log here is ln, that is log to the base e. Now all we need is just to put it in C. Thanks to all who replied my post.

                      G Offline
                      G Offline
                      Gary Kirkham
                      wrote on last edited by
                      #11

                      You can use the code you listed to generate normal variates, but I believe you will get garbage out in the tails of the distribution. The random number generator that is packaged with C is not very good. I suggest you find a better one...there are plenty of them out on the web. Here is an example http://www.cs.wm.edu/~va/software/park/park.html Gary Kirkham A working Program is one that has only unobserved bugs

                      C 1 Reply Last reply
                      0
                      • G Gary Kirkham

                        You can use the code you listed to generate normal variates, but I believe you will get garbage out in the tails of the distribution. The random number generator that is packaged with C is not very good. I suggest you find a better one...there are plenty of them out on the web. Here is an example http://www.cs.wm.edu/~va/software/park/park.html Gary Kirkham A working Program is one that has only unobserved bugs

                        C Offline
                        C Offline
                        Chun Te Ewe
                        wrote on last edited by
                        #12

                        Thanks for the suggestion. I look into it.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups