public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/33815]  New: tr1::uniform_int isn't uniform
@ 2007-10-19  4:35 jkherciueh at gmx dot net
  2007-10-19  9:38 ` [Bug libstdc++/33815] " pcarlini at suse dot de
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: jkherciueh at gmx dot net @ 2007-10-19  4:35 UTC (permalink / raw)
  To: gcc-bugs

Consider:

#include <ctime>
#include <iostream>
#include <vector>
#include <tr1/random>

void test ( unsigned int num_buckets, unsigned int seed = 3141592 ) {
  std::cout << "using " << num_buckets << " buckets:\n";
  std::tr1::mt19937 eng(seed);
  const unsigned long range = eng.max() / 5.5;
  std::tr1::uniform_int<unsigned long> rnd( 0, range );
  std::vector<unsigned long> bucket ( num_buckets, 0 );
  for ( unsigned int i = 0; i < 1000000; ++i ) {
    ++bucket[ rnd(eng) / (range / num_buckets) ];
  }
  for ( unsigned int i = 0; i < num_buckets; ++i ) {
    std::cout << i << ": " << bucket[i] << '\n';
  }
  std::cout << '\n';
}

int main ( void ) {
  test( 2 );
  test( 3 );
  test( 4 );
  test( 6 );
  test( 10 );
  test( 20 );
  test( 30 );
  test( 40 );
}

It yields:

using 2 buckets.
0: 545389
1: 454611

using 3 buckets.
0: 363350
1: 333829
2: 302821

using 4 buckets.
0: 272507
1: 272882
2: 227489
3: 227122

using 6 buckets.
0: 181743
1: 181607
2: 182039
3: 151790
4: 151182
5: 151639

...


This doesn't look uniform. It looks more like the buckets in the
lower half get hit significantly more often.

Credit: This strange behavior had been reported by David Benbennick
to Boost long ago and was apparently never fixed.


-- 
           Summary: tr1::uniform_int isn't uniform
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jkherciueh at gmx dot net
 GCC build triplet: i686-pc-linux
  GCC host triplet: i686-pc-linux
GCC target triplet: i686-pc-linux


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


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

end of thread, other threads:[~2007-10-30 13:05 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-19  4:35 [Bug libstdc++/33815] New: tr1::uniform_int isn't uniform jkherciueh at gmx dot net
2007-10-19  9:38 ` [Bug libstdc++/33815] " pcarlini at suse dot de
2007-10-19  9:40 ` pcarlini at suse dot de
2007-10-19  9:48 ` pcarlini at suse dot de
2007-10-19 10:13 ` jkherciueh at gmx dot net
2007-10-19 10:47 ` pcarlini at suse dot de
2007-10-19 10:49 ` pcarlini at suse dot de
2007-10-19 11:26 ` pcarlini at suse dot de
2007-10-19 17:36 ` paolo at gcc dot gnu dot org
2007-10-20 10:02 ` paolo at gcc dot gnu dot org
2007-10-20 10:03 ` paolo at gcc dot gnu dot org
2007-10-20 10:05 ` pcarlini at suse dot de
2007-10-20 11:07 ` jkherciueh at gmx dot net
2007-10-20 11:27 ` pcarlini at suse dot de
2007-10-21  9:49 ` jkherciueh at gmx dot net
2007-10-21 11:33 ` pcarlini at suse dot de
2007-10-30 13:05 ` paolo at gcc dot gnu dot org

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