* g++ & rand() in Cygwin
@ 2005-03-12 9:26 Alex Vinokur
2005-03-12 14:44 ` Brian Budge
2005-03-20 19:02 ` Gerrit P. Haase
0 siblings, 2 replies; 4+ messages in thread
From: Alex Vinokur @ 2005-03-12 9:26 UTC (permalink / raw)
To: gcc-help; +Cc: cygwin
------ foo.cpp ------
#include <cstdlib>
#include <iostream>
using namespace std;
int main ()
{
cout << rand() << endl;
cout << rand() << endl;
return 0;
}
---------------------
// g++ version 3.3.3 (cygwin special)
$ g++ foo.cpp
The program below generates the following output:
-----------
0
1481765933
-----------
First pseuso-random number is 0.
Is it by purpose?
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: g++ & rand() in Cygwin
2005-03-12 9:26 g++ & rand() in Cygwin Alex Vinokur
@ 2005-03-12 14:44 ` Brian Budge
2005-03-20 19:02 ` Gerrit P. Haase
1 sibling, 0 replies; 4+ messages in thread
From: Brian Budge @ 2005-03-12 14:44 UTC (permalink / raw)
To: Alex Vinokur; +Cc: gcc-help, cygwin
Hi Alex -
You should seed the rng first before using it. Also, there are much
better rngs out there than rand (though it's much better than it used
to be). I tend to plug for Mersenne Twister which is both faster,
produces better random numbers, and can be used in a parallel
programming environment.
Brian
On Sat, 12 Mar 2005 08:04:59 +0200, Alex Vinokur
<alexvn@users.sourceforge.net> wrote:
> ------ foo.cpp ------
> #include <cstdlib>
> #include <iostream>
> using namespace std;
> int main ()
> {
> cout << rand() << endl;
> cout << rand() << endl;
> return 0;
> }
> ---------------------
>
> // g++ version 3.3.3 (cygwin special)
>
> $ g++ foo.cpp
>
> The program below generates the following output:
> -----------
> 0
> 1481765933
> -----------
>
> First pseuso-random number is 0.
>
> Is it by purpose?
>
> --
> Alex Vinokur
> email: alex DOT vinokur AT gmail DOT com
> http://mathforum.org/library/view/10978.html
> http://sourceforge.net/users/alexvn
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: g++ & rand() in Cygwin
2005-03-12 9:26 g++ & rand() in Cygwin Alex Vinokur
2005-03-12 14:44 ` Brian Budge
@ 2005-03-20 19:02 ` Gerrit P. Haase
2005-03-21 8:47 ` Nathan Sidwell
1 sibling, 1 reply; 4+ messages in thread
From: Gerrit P. Haase @ 2005-03-20 19:02 UTC (permalink / raw)
To: Alex Vinokur; +Cc: cygwin, gcc-help
Alex Vinokur wrote:
> ------ foo.cpp ------
> #include <cstdlib>
> #include <iostream>
> using namespace std;
> int main ()
> {
> cout << rand() << endl;
> cout << rand() << endl;
> return 0;
> }
> ---------------------
>
>
> // g++ version 3.3.3 (cygwin special)
>
> $ g++ foo.cpp
>
> The program below generates the following output:
> -----------
> 0
> 1481765933
> -----------
>
> First pseuso-random number is 0.
>
> Is it by purpose?
I don't know. I use MT for random number generation:
http://anfaenger.de/cygwin/MersenneTwister/
Gerrit
--
=^..^=
Action Soccer: http://www.action-soccer.de/?lv=de&id=505
(german online game)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: g++ & rand() in Cygwin
2005-03-20 19:02 ` Gerrit P. Haase
@ 2005-03-21 8:47 ` Nathan Sidwell
0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2005-03-21 8:47 UTC (permalink / raw)
To: Gerrit P. Haase; +Cc: Alex Vinokur, cygwin, gcc-help
Gerrit P. Haase wrote:
> Alex Vinokur wrote:
>> First pseuso-random number is 0.
Random nnumber generators generally need to be seeded with a random
seed. This naively strange behaviour allows you to get consistent
sequences of random numbers, which is generally necessary for regression
testing and debugging.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-03-20 19:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-12 9:26 g++ & rand() in Cygwin Alex Vinokur
2005-03-12 14:44 ` Brian Budge
2005-03-20 19:02 ` Gerrit P. Haase
2005-03-21 8:47 ` Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).