Pcl: [PCL] Use C++11 random generators, not `rand`

Created on 23 Mar 2020  路  7Comments  路  Source: PointCloudLibrary/pcl

Context

rand has several issues, which C++11 random generators don't. New PR often see the rand usage and try to emulate the wrong behavior.

Expected behavior

Remove all rand so when people search for how PCL did its random num generation, they get good quality results

Additional context

Usage of old-fashioned rand discovered by codacity (or maybe try grep)

medium good first issue todo

Most helpful comment

Yes, and maybe add a documentation there to use random_engine to generate the seed and not time or any other weird usage (except a constant seed)

All 7 comments

There is already UniformGenerator in random.h and CloudGenerator in generator.h.
We should use that only right?

Yes, and maybe add a documentation there to use random_engine to generate the seed and not time or any other weird usage (except a constant seed)

rand has used a lot, especially for testing.
I'm working on replacing to UniformGenerator. But is there a way to eliminate rand usage in the future?

is there a way to eliminate rand usage in the future?

Usage in C++ (in general) or in PCL?

In PCL.
I've dumped files involved with rand(), hundreds.
Most of them are found in test files. Perhaps using rand() in testing is more convenient and straight-forward for most people. This makes me think if there's a way to avoid using rand() in the future.

in testing is more convenient

We're talking about the PCL source code, not the application code that users of PCL write. Please feel free to use rand or the better alternatives provided in PCL: UniformGenerator and CloudGenerator.

Marking this as stale due to 30 days of inactivity. It will be closed in 7 days if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings