public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/44653]  New: A uniform_real random distribution produces invalid floating-point random numbers
@ 2010-06-24  9:28 dchichkov at gmail dot com
  2010-06-24  9:54 ` [Bug libstdc++/44653] " dchichkov at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dchichkov at gmail dot com @ 2010-06-24  9:28 UTC (permalink / raw)
  To: gcc-bugs

According to:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1452.html

[quote] A uniform_real random distribution produces floating-point random
numbers x in the range min <= x <= max, with equal probability. min and max are
the parameters of the distribution. [/unqoute]


Following code (with either -std=c++0x or -std=gnu++0x):
#include <tr1/random>
#include <iostream>

int main()
{
 std::tr1::mt19937 e;
 std::tr1::uniform_real<double> dist(0.0, 1.0);
 std::cout << dist(e) << std::endl;
 return 0;
}

Produces: 3.49921e+09. It should produce a value between [0.0, 1.0). Not some
wild int.


-- 
           Summary: A uniform_real random distribution produces invalid
                    floating-point random numbers
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dchichkov at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44653


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/44653] A uniform_real random distribution produces invalid floating-point random numbers
  2010-06-24  9:28 [Bug libstdc++/44653] New: A uniform_real random distribution produces invalid floating-point random numbers dchichkov at gmail dot com
@ 2010-06-24  9:54 ` dchichkov at gmail dot com
  2010-06-24  9:57 ` paolo dot carlini at oracle dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: dchichkov at gmail dot com @ 2010-06-24  9:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from dchichkov at gmail dot com  2010-06-24 09:53 -------
Update. Following code produces the correct value:

#include <functional>
#include <random>
#include <iostream>

int main()
{
 typedef std::mt19937 eng_t;
 typedef std::uniform_real<double> dist_t;
 typedef std::variate_generator <eng_t, dist_t > gen_t;
 eng_t eng;
 dist_t dist(0.0, 1.0);
 gen_t gen(eng, dist);

 std::cout << gen() << std::endl;
 return 0;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44653


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/44653] A uniform_real random distribution produces invalid floating-point random numbers
  2010-06-24  9:28 [Bug libstdc++/44653] New: A uniform_real random distribution produces invalid floating-point random numbers dchichkov at gmail dot com
  2010-06-24  9:54 ` [Bug libstdc++/44653] " dchichkov at gmail dot com
@ 2010-06-24  9:57 ` paolo dot carlini at oracle dot com
  2010-06-24 10:00 ` paolo dot carlini at oracle dot com
  2010-06-24 10:00 ` paolo dot carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-06-24  9:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2010-06-24 09:57 -------
Indeed, that is what you should use for the TR1 random. Note that we have been
trying to also deliver a conforming C++0x (thus, in std::) <random> only
lately, in 4.3.x we delivered the TR1 code in the std:: namespace too. Thus, if
you want to experiment with the C++0x version, use 4.5.x or mainline.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44653


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/44653] A uniform_real random distribution produces invalid floating-point random numbers
  2010-06-24  9:28 [Bug libstdc++/44653] New: A uniform_real random distribution produces invalid floating-point random numbers dchichkov at gmail dot com
                   ` (2 preceding siblings ...)
  2010-06-24 10:00 ` paolo dot carlini at oracle dot com
@ 2010-06-24 10:00 ` paolo dot carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-06-24 10:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from paolo dot carlini at oracle dot com  2010-06-24 10:00 -------
Reopen...


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44653


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug libstdc++/44653] A uniform_real random distribution produces invalid floating-point random numbers
  2010-06-24  9:28 [Bug libstdc++/44653] New: A uniform_real random distribution produces invalid floating-point random numbers dchichkov at gmail dot com
  2010-06-24  9:54 ` [Bug libstdc++/44653] " dchichkov at gmail dot com
  2010-06-24  9:57 ` paolo dot carlini at oracle dot com
@ 2010-06-24 10:00 ` paolo dot carlini at oracle dot com
  2010-06-24 10:00 ` paolo dot carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-06-24 10:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo dot carlini at oracle dot com  2010-06-24 10:00 -------
... to resolve as duplicate.

*** This bug has been marked as a duplicate of 40263 ***


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44653


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-06-24 10:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-24  9:28 [Bug libstdc++/44653] New: A uniform_real random distribution produces invalid floating-point random numbers dchichkov at gmail dot com
2010-06-24  9:54 ` [Bug libstdc++/44653] " dchichkov at gmail dot com
2010-06-24  9:57 ` paolo dot carlini at oracle dot com
2010-06-24 10:00 ` paolo dot carlini at oracle dot com
2010-06-24 10:00 ` paolo dot carlini at oracle dot com

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).