473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Gaussian random variable

bob
I was wondering if anyone can recommend a way to generate a Gaussian
random variable with standard deviation 1.

Thank you.

Mar 30 '07 #1
3 7762
* bo*@coolgroups.com:
I was wondering if anyone can recommend a way to generate a Gaussian
random variable with standard deviation 1.
Unfortunately the standard library doesn't help you much in this regard.

Check the net. Also, IIRC, the Smalltalk books had some examples.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 30 '07 #2
bo*@coolgroups.com wrote:
I was wondering if anyone can recommend a way to generate a Gaussian
random variable with standard deviation 1.

Thank you.
Nothing C++ about this question. Followups set to comp.programming.

Here's one very general approach that can also be applied to your question:

For a general distribution D(x) consider the integral of that
distribution G(x) = integral_{-infinity}^x D(y) dy. The range of G(x)
is then [0,1]. Pick a value z uniformly at random in [0,1] and consider
the inverse function G^{-1}(z). Then the distribution of values of
G^{-1}(z) obeys the original distribution D.

That may sound complicated but it's really not. You have a standard
normal distribution N(x). Integrate that distribution to get:

f(x) = 1/2 (1 + erf(x/sqrt(2))).

Now pick values uniformly at random in [0,1], which ought to be easy
(approximately) in most languages. Then compute f-inverse of those
values to get values obeying a Gaussian distribution. The hard part
here will be inverting the erf function. You'll probably have to rely
on some sort of library for this (or numerically integrate N(x) yourself
and create a lookup table of values of f(x)).

Mark
Mar 30 '07 #3
On Mar 30, 7:16 am, b...@coolgroups.com wrote:
I was wondering if anyone can recommend a way to generate a Gaussian
random variable with standard deviation 1.
If you can use Boost, Boost::random has a normal_distribution
class, which you can use with any of its random generator
classes. (Note that this is also in TR1, and will be part of
the next version of C++, so it's possible that your compiler
already supports it.)

See http://www.boost.org/libs/random/ran...ributions.html
for the documentation.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Mar 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Roman Töngi | last post by:
I want to get a random number between 0 and 1. The following code works but it seems to me a litte awkward. Is there a "better" solution. double rnd; int integerRnd; ...
6
by: Mike Langworthy | last post by:
i can not seem to get this code to work. someone please help using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
6
by: A2 | last post by:
How would i make a script that would pick a random variable ex. I would have and array and the script would pick one of variables???
22
by: Ivan Voras | last post by:
Hi, I have a list of items, and need to choose several elements from it, "almost random". The catch is that the elements from the beginning should have more chance of being selected than those...
2
by: Ardeshir | last post by:
I need help to generate Poisson random variable via Inverse Transform .
4
by: Kevin G. | last post by:
Hello all, I have a flat HTML page with 3 distinct HTML tables, and I'm trying to randomly display the tables when the page loads, without repeating. My idea is to use the PHP include() function...
16
by: raylopez99 | last post by:
For the public record. RL public void IterateOne() { Random myRandom = new Random(); //declare Random outside the iteration for (int j = 0; j < Max; j++) {
2
by: shshshsh | last post by:
how can i caste random variable to integer in c#?
2
by: ritesh247 | last post by:
Hey, I am doing a project on one of my modules and I am supposed to build a function that gives uniform random variable between lets say Y and Z...I was wondering how this function can be built?? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.