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

Use std::mt19937 to replace mt_random. #221

Closed
wants to merge 4 commits into from

Conversation

lgc1112
Copy link
Collaborator

@lgc1112 lgc1112 commented Sep 11, 2023

Use td::mt19937 to replace mt_random.

@lgc1112
Copy link
Collaborator Author

lgc1112 commented Sep 11, 2023

At least 1 approving review is required by reviewers with write access.

Copy link
Owner

@lailongwei lailongwei left a comment

Choose a reason for hiding this comment

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

建议处理mtrandom的min/max的值兼容

@@ -21,8 +21,8 @@

#pragma once

#include <random>
Copy link
Owner

Choose a reason for hiding this comment

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

建议进行优化:

  • #include <random>放到OSHeader.h中(找到合适位置) or 考虑隐藏std::mt19937实现(即RandomInl.h改名为Random.cpp,但会有可能性能损失(call 性能))

@@ -30,19 +30,19 @@ inline LLBC_Random::LLBC_Random(int seed)

inline void LLBC_Random::Seed(int seed)
{
_mtRand.reset(seed);
_mtRand.seed(seed);
Copy link
Owner

Choose a reason for hiding this comment

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

建议查阅api文档,确保Seed()接口跟seed()的参数类型一致

}

inline int LLBC_Random::Rand(int end)
{
if (LIKELY(end != 0))
{
const long long randVal = llabs(static_cast<int>(_mtRand.rand()));
const long long randVal = llabs(static_cast<int>(_mtRand()));
Copy link
Owner

Choose a reason for hiding this comment

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

long long建议修改为sint64,以明确长度

Copy link
Owner

@lailongwei lailongwei left a comment

Choose a reason for hiding this comment

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

部分代码可以优化,从可读性兼容性角度

@lailongwei lailongwei closed this Nov 25, 2023
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.

2 participants