C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

I Don't UnderstRand();

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
charlesrkiss
Guest





PostPosted: Wed Jun 08, 2005 8:08 am    Post subject: I Don't UnderstRand(); Reply with quote



http://random.mat.sbg.ac.at/~charly/server/node3.html

I have to say that I'm feeling a little lost. The information here is
unbelievably great! It's going to take me a few days just to go
through it all. I particulary like the /dev/random and will somehow
have to get it to work; for now, I get these errors:

charles@house:~$ g++ game/t.C -o t
game/t.C: In function `int main()':
game/t.C:18: implicit declaration of function `int perror(...)'

when compiling the following code:

include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

const char *rand_device = "/dev/urandom";
// const char *rand_device = "/dev/random";

int
main() {
int getuid();


cout << "uid " << getuid() << endl;
std::ifstream random(rand_device);
if (!random) {
perror(rand_device);
return 1;
}

unsigned int seed;
random.read((char*)&seed, sizeof(seed));
cout << "seed: " << seed << endl;
return 0;
}


that's whether I comment out the /dev/urandom or the /dev/random.

As far as the pseudo and "non-pseudo" random number debate is
concerned; I'd like to add that randomness is not necessarily the
logical complement of predictability. For example, if I roll a pair of
dice several hundred times (something I'm not so sure would generate
absolutely random autcomes) and record the results of each throw, I
should have an array of hundreds of elements, randomly generated, whose
values are between one and twelve. I can then, supposedly, use the
array as a set of randomly generated numbers; in a program or in a game
for example.

However, if I share the record of outcomes with some others and not
share it with others, and we all play the game, the game is no longer
fair; but the values were still randomly generated.

Is rand() an array of absolutely randomly generated numbers, despite
the predictable nature of the information which is shared? Or is it
not really that random AND the predictable nature of the information is
shared?

Meanwhile, I noticed I have some *rand48 statements in my
/usr/include/stdlib.h file. I heard these are better PRNG's.

I still would like to know your thoughts on the distiction between
randomness and predictability with repect to these functions -the
reason why is because my interest is not in the securability, nor
predictability of the outcomes in using these fuctions; but only their
randomness. I got a really great link here, that I'm still reading:

http://random.mat.sbg.ac.at/~charly/server/node3.html

I'm not even sure anything is even random anymore. Certainly, if there
exists some determinism (if not complete) to our experience we should
have trouble in generating completely unpredictable random numbers.
The problem is fascinating. I keep thinking of a switch that turns on
a low frequency wave, that will generate a particle of disturbance
every second (or so, decay); and then it would be up to the clock on
the detector to be of a high enough period to check the detector a
multiple of times, and then to record the detection as a number of
units of time (numbers of beats of the clock) after the switch was
initially turned on. The randomness would then be a function of the
ratio of the expectation value (low frequency) divided by the frequency
of the clock on the detector (high frequency). But that hardware would
require an amount of nuclear waste in our CPU's! Would it be better to
have an element of complete unpredictablilty in our CPU's and less
nuclear waste in Yucca Mountain, or have I completely wasted your
time??

So, what's more random /dev/*random or *rand*()?

Again,

Thanks for the great info!!

Charles


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
zeotherm
Guest





PostPosted: Fri Jun 10, 2005 10:24 am    Post subject: Re: I Don't UnderstRand(); Reply with quote



A few items to note, if you want to use perror, then you need to
include cstdio. However the C++ way of outputting to the standard
error strem is to use cerr. e.g.
cerr << rand_device << endl;

As far as random number generators go, I would stay away from linear
congruent generators (such as the system supplied rand()). When
dealing with random numbers keep this is mind: A computer is one of
the least random machines ever built, therefore it can in no way
generate a random number. If you want a good random number generator I
would suggest looking into the Mersenne Twist generator. You can
google for it and find many references to it and it's source code. I
believe that TR1 will include it, and I think boost already has it. To
answer your final question, I would NOT use the system supplied rand().
I don't know enough about /dev/*random to give reccomendations. I'd
look into the Mersenne Twister for a good RNG. Best of luck with it.

- ZT

Decent Random Number generation discussion:
http://www.qbrundage.com/michaelb/pubs/essays/random_number_generation


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.