Boost logo

Boost Users :

Subject: Re: [Boost-users] Random Numbers using Boost.
From: Mike Marchywka (marchywka_at_[hidden])
Date: 2009-01-13 08:03:23


----------------------------------------
> Date: Mon, 12 Jan 2009 20:56:11 -0800
> To: boost-users_at_[hidden]
> From: marshall_at_[hidden]
> Subject: Re: [Boost-users] Random Numbers using Boost.
>
> At 7:21 PM -0600 1/12/09, Atul Kulkarni wrote:
>>Hi All,
>>
>>I am using boost::random for generating random numbers I am using
>>the default quick start code given up on the web page. I want to
>>generate random numbers between range 1 - n so that they do not
>>repeat themselves for at least n numbers.

I'm not sure if shuffling is the best approach as described
on wiki as it suggests an indirect method using random numbers to
shuffle a set of unique entries. The polynomial approach is more
direct and may be worth considering.
 
You want some kind of pseudorandom generator, something based on
a polynomial would be worth considering. Essentially you want a
counter modulo n and a look up table ( presumably with no repeating
entries which you could generate from the shuffing approach cited earlier). Think about something like your output sequence g generated from
 g(n+1)=(F(g(n))%n where you
need to constrain F so that the period isn't reduced.
 
http://www.google.com/search?hl=en&q=pseudorandom++polynomial+site%3Awikipedia.org
 
 
This is just a state machine with a concise transition rule.
 
 
>>
>>1. Is it possible using boost::random?
>>2. If it is possible what do I need to do except the below code.
>>
>>==
>> boost::mt19937 rng1;
>> boost::uniform_int<> six1(1,30);
>> boost::variate_generator>>boost::uniform_int<>> die1(rng1, six1);
>> for(int i=0; i < 29; i++)
>> {
>> cout<>> }
>>==
>
> This will not satisfy your preconditions, except by accident.
> A random number generator will, at random times, output the same
> number twice in a series.
>
> If you want to choose numbers w/o repeating, that's more akin to
> shuffling the cards in a deck - and there are lots of online
> resources on how to do that (alternately, you can look in Knuth).
> See for one.
>
> --
> -- Marshall
>
> Marshall Clow Idio Software
>
> It is by caffeine alone I set my mind in motion.
> It is by the beans of Java that thoughts acquire speed,
> the hands acquire shaking, the shaking becomes a warning.
> It is by caffeine alone I set my mind in motion.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
_________________________________________________________________
Windows Live™ Hotmail®: Chat. Store. Share. Do more with mail.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_hm_justgotbetter_explore_012009


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