| delorie.com/archives/browse.cgi | search |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| Message-ID: | <5b70945805031201261b6beac1@mail.gmail.com> |
| Date: | Sat, 12 Mar 2005 10:26:24 +0100 |
| From: | Brian Budge <brian DOT budge AT gmail DOT com> |
| Reply-To: | Brian Budge <brian DOT budge AT gmail DOT com> |
| To: | Alex Vinokur <alexvn AT users DOT sourceforge DOT net> |
| Subject: | Re: g++ & rand() in Cygwin |
| Cc: | gcc-help AT gcc DOT gnu DOT org, cygwin AT cygwin DOT com |
| In-Reply-To: | <d0u0pt$aj0$1@sea.gmane.org> |
| Mime-Version: | 1.0 |
| References: | <d0u0pt$aj0$1 AT sea DOT gmane DOT org> |
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 AT users DOT sourceforge DOT 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
>
>
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |