Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to <random> #195

Merged
merged 2 commits into from
Aug 12, 2021
Merged

migrate to <random> #195

merged 2 commits into from
Aug 12, 2021

Conversation

v4hn
Copy link
Contributor

@v4hn v4hn commented Aug 11, 2021

rand/srand were probably already deprecated by the time this code was written...
I took the error on MoveIt's CI as an incentive to migrate to std::random:

As example code referred to a seeding step, I added an explicit setRandomSeed to the API.

This is required to fix MoveIt's CI: moveit/moveit@2989f44

<<<
rviz_visual_tools.cpp:2810:42: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-int-float-conversion]
float d = static_cast(rand()) / RAND_MAX;
~ ^~~~~~~~
/usr/include/stdlib.h:86:18: note: expanded from macro 'RAND_MAX'
^~~~~~~~~~
<<<

Please review @nbbrooks @tylerjw @JafarAbdi

rand/srand were probably already deprecated by the time this code was written...
I took the error on MoveIt's CI as an incentive to migrate to std::random:

As example code referred to a seeding step, I added an explicit setRandomSeed to the API.

<<<
rviz_visual_tools.cpp:2810:42: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-int-float-conversion]
  float d = static_cast<float>(rand()) / RAND_MAX;
                                       ~ ^~~~~~~~
/usr/include/stdlib.h:86:18: note: expanded from macro 'RAND_MAX'
                          ^~~~~~~~~~
<<<
@@ -1144,6 +1152,8 @@ class RvizVisualTools
// Chose random colors from this list
static const std::array<colors, 14> ALL_RAND_COLORS;

static std::mt19937 mt_random_engine_;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because dRand, fRand, and iRand are and I did not want to break API by removing static from them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if at least one other team member agrees, I'm also open to change them to non-static members, but that might entail more changes in other places/repos

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this out of expedience to get moveit CI working again, if we want to a further refactoring of this later we can.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because dRand, fRand, and iRand are and I did not want to break API by removing static from them.

Oh, interesting. And you mean ABI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ABI?

No, API.
RvizVisualTools::iRand(0,1) would not compile anymore if we remove static.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o. I was asking about mt_random_engine_, not iRand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but how would you want to access a non-static random engine from the static iRand?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@griswaldbrooks griswaldbrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we accepting formatting comments?

@v4hn
Copy link
Contributor Author

v4hn commented Aug 12, 2021

Are we accepting formatting comments?

@tylerjw tylerjw merged commit 5d0a618 into PickNikRobotics:master Aug 12, 2021
@griswaldbrooks
Copy link

Don't worry about it. There was some comma spacing I was going to ask about but if the linter is fine with it then I don't care.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants