Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost random not looking so random
From: Lars Viklund (zao_at_[hidden])
Date: 2012-10-28 02:06:02


On Sat, Oct 27, 2012 at 09:30:45PM -0700, Robin Rowe wrote:
> I'm using boost to shuffle an array, but it's not looking as random as I
> would expect. Am I not using it right?

Randomness doesn't give a hoot about discernable patterns. A generator
that avoids "non-random patterns" would be properly defective.

If you want to measure the randomness of something, consider using
the proper statistical tests designed to measure the uncorrellation of
sources.

> The code below outputs sequences that look random mostly, but I see
> patterns such as 7 7 12 12 11.
>
> boost::random::mt19937 rng;
> boost::minstd_rand lcggen;
> lcggen.seed(clockTime);
> rng.seed(lcggen);
> unsigned min=1;
> unsigned max=15;
> 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, but ocular observation is still not a reliable
metric for that.

-- 
Lars Viklund | zao_at_[hidden]

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