I need to generate random number with Boost Random.
I tried to follow the general guide.
I extracted the files of the library. So if I want to use the classes and objectj of the library how I should do?
First I know including the library in the program. Then I have to compile the library and the program.cpp itself? (And both with the same compiler - I'm using g++).
I am using a virtual box of ubuntu. It is first time that I am using library so I really don't know.
So, you use a real number distribution.
I'm not this kind of "getting started" is the best fit for StackOverflow, but I'll give you this quick hints:
In your Ubuntu virtual box:
Create a file using your favourite editor. If you have none,
gedit main.cpp
ornano main.cpp
is a start:Now compile it using
The program is now ready to run: Live On Coliru
Printing
Seeding && Non-Header Only Libraries
The above works because the Boost Random library is mostly header only. What if you wanted to use the
random_device
implementation to seed the random generator?Live On Coliru
Now you'll have to link as well: Compiling with
Now the output will be different each run.
BONUS: Standard Library instead of Boost
You don't need Boost here at all:
Live On Coliru
Compile with
And run it again with
./demo
BONUS
Showing a whole gamut of distributions that have mean=0 and stddev=1:
Live On Coliru
Prints