-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
At least 1 approving review is required by reviewers with write access. |
There was a problem hiding this 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> |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
long long
建议修改为sint64
,以明确长度
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
部分代码可以优化,从可读性跟兼容性角度
Use td::mt19937 to replace mt_random.