473,396 Members | 1,683 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,396 software developers and data experts.

boost random

Hi

using The Boost Random Number Library. how can I get a random number
every time I run the project "./proj"

the code below prints out 10 random numbers but it will print the same
exact numbers every time it runs. I just need one number not 10, and
random "different from the one before".
I can do the first "remove the for loop" but not able to do the
second.

#include <boost/random.hpp>
typedef boost::minstd_rand base_generator_type;
int main(){
base_generator_type generator(42u);
boost::uniform_real<uni_dist(0,1);
boost::variate_generator<base_generator_type&, boost::uniform_real< uni(generator, uni_dist);
for(int i=0; i<10; i++)
std::cout << uni() << std::endl;
}

thanks
Nov 20 '06 #1
2 5453
I don't know much about the boost library, but is it not possible to
give a seed number. If it is then you can make your seed number
depending on the time when the program starts to run.

Klaas

Gary Wessle wrote:
Hi

using The Boost Random Number Library. how can I get a random number
every time I run the project "./proj"

the code below prints out 10 random numbers but it will print the same
exact numbers every time it runs. I just need one number not 10, and
random "different from the one before".
I can do the first "remove the for loop" but not able to do the
second.

#include <boost/random.hpp>
typedef boost::minstd_rand base_generator_type;
int main(){
base_generator_type generator(42u);
boost::uniform_real<uni_dist(0,1);
boost::variate_generator<base_generator_type&, boost::uniform_real< uni(generator, uni_dist);
for(int i=0; i<10; i++)
std::cout << uni() << std::endl;
}

thanks
Nov 20 '06 #2
Hi

Klaas Vantournhout wrote:
I don't know much about the boost library, but is it not possible to
give a seed number. If it is then you can make your seed number
depending on the time when the program starts to run.
Of course it is:
Gary Wessle wrote:
> base_generator_type generator(42u);
And while 42 is the answer to basically everything, it is not a good seed.
( e.g. clock() might be much better, on UNIces, reading from /dev/random
would provide a good seed )

Markus
Nov 20 '06 #3

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

Similar topics

2
by: lallous | last post by:
Hello Many are saying that Boost will be included in the c++ standard...Does that mean that every new compiler release will have Boost included with it in order conform to portability? Does...
7
by: sbobrows | last post by:
{Whilst I think much of this is OT for this newsgroup, I think the issue of understanding diagnostics just about gets under the door. -mod} Hi, I'm a C++ newbie trying to use the Boost regex...
1
by: John C | last post by:
Hi, I am trying to include the generation of random numbers in my c++ class. However I don't quite know how to incorporate it. To start with, I managed to get random numbers going via the...
2
by: toton | last post by:
Hi, I am trying to use boost::range with one of my own container class, and having some problem. I am missing some usage of range. Can anyone suggest a proper way for it ? To show the problem...
1
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
1
by: cutebravo | last post by:
Enhance your knowledge and boost your mind A great way to improve your knowledge is a technique I used when I was a student. After I had finished reading a book, I took a few blank sheets and...
2
by: Alex Vinokur | last post by:
Hi, I need to generate randomal integers (0 - 2^31) with boost::minstd_rand. Any sample of minstd_rand usage? Thanks in advance, Alex Vinokur
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
7
by: BubbaT | last post by:
What is the best way to pick up Boost? Thanks BubbaT
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.