|
Boost Users : |
From: Richard Dingwall (rdingwall_at_[hidden])
Date: 2007-10-04 20:39:15
On 10/5/07, Jeffrey Holle <jeffreyholle_at_[hidden]> wrote:
> I am at the point in my application where I must introduce randomness to
> a sort routine. Basically when 2 elements are equal, I need to create a
> 50% probability that they will be swapped.
>
> What is the correct boost::random library resource to code this?
>
> I've attempted to use uniform_01, by creating an instance of it with
> this type:
> typedef boost::uniform_01<boost::minstd_rand, double> rand_gen_t;
>
> However, after getting it constructed as a class attribute, I find
> accessing it with:
> cout << (*pRand_gen++) << endl;
Try:
cout << (*pRand_gen++) % 2 << endl;
Richard
>
> It produces numbers like 1 134784888 134784288 2 134784845 134784224
> 134785176 5 0 134784376 134785328 0.
>
> What I want is a sequence like 0 1 0 1 0 1 0 0 0 1 1 1 1 0 1 0 1 that is
> sort of random.
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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