Random class

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Random class

Julien Demouth
Hi all,

Maybe it is a question which has already been raised (I've seen no sign
of this in the archive of the list) but why does the CGAL::Random
documentation page differ from its implementation ?

Is there any plan of designing a "better" Random class ? Especially
because the actual implementation may lead to weird behaviors, as with
the following code:

for (int i = 0 ; i < 10 ; ++i)
{
     CGAL::Triangulation_hierarchy_3 dt;
     std::vector<...> pts;
     CGAL::Random_points_on_sphere_3<...> gen;
     CGAL::copy_n (gen, 64, std::back_inserter (pts));
     dt.insert (pts.begin (), pts.end ());
     ...
}

Each loop produces the same set of points (and of course the same
triangulation of these points). Indeed, the default constructor of
Triangulation_hierarchy_3 creates a Random object which calls std::srand
with a seed value of 0. It's a bit annoying and it may take some time to
understand the problem :(

Best,
Julien


--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Random class

Sylvain Pion
Administrator
Julien Demouth a écrit :
> Hi all,
>
> Maybe it is a question which has already been raised (I've seen no sign
> of this in the archive of the list) but why does the CGAL::Random
> documentation page differ from its implementation ?
>
> Is there any plan of designing a "better" Random class ?

I would say the plan will be to try to switch to the random generators
provided by C++0x (the next C++ standard).  I know our random generators
have some issues.

--
Sylvain Pion
INRIA Sophia-Antipolis
Geometrica Project-Team
CGAL, http://cgal.org/


smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Random class

Bernd Gaertner
In reply to this post by Julien Demouth
Julien Demouth wrote:
> Hi all,
>
> Maybe it is a question which has already been raised (I've seen no sign
> of this in the archive of the list) but why does the CGAL::Random
> documentation page differ from its implementation ?

In which respect does it differ?

> Is there any plan of designing a "better" Random class ?

If you mean the fact that you get the same sequence when you use the
same seed, then I don't think it's bad. After all, it must be possible
to reproduce the "random" data that for example lead to a failing run of
an algorithm.

Best,
Bernd.
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Random class

Bo Schwarzstein-2
In reply to this post by Sylvain Pion
GSL(GNU Scientific Library) provides a lot of classical random generators
and quasi monte carlo sequences generators. The boost library also owns
random generators, it's easy to use.

--------------------------------------------------
From: "Sylvain Pion" <[hidden email]>
Sent: Tuesday, July 22, 2008 9:14 PM
To: <[hidden email]>
Subject: Re: [cgal-discuss] Random class

> Julien Demouth a �crit :
>> Hi all,
>>
>> Maybe it is a question which has already been raised (I've seen no sign
>> of this in the archive of the list) but why does the CGAL::Random
>> documentation page differ from its implementation ?
>>
>> Is there any plan of designing a "better" Random class ?
>
> I would say the plan will be to try to switch to the random generators
> provided by C++0x (the next C++ standard).  I know our random generators
> have some issues.
>
> --
> Sylvain Pion
> INRIA Sophia-Antipolis
> Geometrica Project-Team
> CGAL, http://cgal.org/
>
>
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Random class

Julien Demouth
In reply to this post by Bernd Gaertner
Bernd Gaertner a écrit :
> Julien Demouth wrote:
>> Hi all,
>>
>> Maybe it is a question which has already been raised (I've seen no
>> sign of this in the archive of the list) but why does the CGAL::Random
>> documentation page differ from its implementation ?
>
> In which respect does it differ?

The implementation of Random class does not contain the type
Random::State and member functions save_state and restore_state.
Actually, it does not use internal states and does not respect the
sentence "Different streams are independent of each other" [CGAL online
doc, Ref. Manual of class Random, line 3 of Sec. Definition].

>> Is there any plan of designing a "better" Random class ?
>
> If you mean the fact that you get the same sequence when you use the
> same seed, then I don't think it's bad. After all, it must be possible
> to reproduce the "random" data that for example lead to a failing run of
> an algorithm.

I agree, having the same sequence when you use the same seed is a good
thing. The problem I wanted to emphasize is that Random instances are
not independent. Thus, if you create a new Random instance (as it is the
case when you create an instance of Triangulation_hierarchy_3), it
reinitializes the internal state of _all_ your Random instances. To make
it more concrete, I had an instance of Random to generate random points
but each time I created a new Triangulation_hierarchy_3, the internal
state used by my Random instance was modified. It took me some time to
understand the problem.

Best,
Julien

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://lists-sop.inria.fr/wws/info/cgal-discuss