|
Boost Users : |
Subject: Re: [Boost-users] Boost random not looking so random
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2012-10-28 07:42:01
> > I'm using boost to shuffle an array, but it's not looking as random as I
> > would expect.
> > for(unsigned i=0;i<5;i++)
> > { boost::random::uniform_int_distribution<> dist(min,max);
> > const int j = dist(rng);
> > ... code that shuffles stuff using j ...
> > min++;
> > cout<<j<<' ';
> > }
>
> You may of course be using the results of an uniform distribution in a
> way that causes the resulting shuffle have some configurations that are
> more likely than others...
Use std::shuffle from the algorithm header. This stuff is tricky to get
right if you write it yourself. Google "Knuth shuffle" for some background.
- Rhys
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net