This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
util: make rand a standalone util decoupled from rdsn runtime #163
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
neverchanje
requested review from
qinzuoyan,
shengofsun,
acelyc111,
hycdong,
zhangyifan27,
vagetablechicken and
mentoswang
September 20, 2018 04:21
shengofsun
previously approved these changes
Sep 20, 2018
include/dsn/utility/rand.h
Outdated
namespace dsn { | ||
namespace rand { | ||
|
||
// uint64n returns, as an uint64_t, a non-negative pseudo-random number in [min, max]. |
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.
注视是uint64n, 代码是uint64in。
不过这命名没看懂,n和in代表啥?
src/core/core/rand.cc
Outdated
@@ -0,0 +1,21 @@ | |||
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. |
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.
文件名还是统一用cpp吧
include/dsn/utility/rand.h
Outdated
inline uint64_t uint64() { return uint64in(0, std::numeric_limits<uint64_t>::max()); } | ||
|
||
// float64 returns, as a double, a pseudo-random number in [0.0,1.0]. | ||
inline double float64n() { return uint64in(0, 1000000000) / 1000000000.0; } |
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.
float64n的命名反而不如原来的probability好。因为概率一定是[0, 1]的,而float不一定是
@shengofsun 之前的命名根据 golang 的 math.rand,https://golang.org/pkg/math/rand/ 现在按你的批评改成更 c++ 风格的命名,另外修缮了注释,你可以看一下 |
shengofsun
approved these changes
Sep 21, 2018
acelyc111
approved these changes
Sep 24, 2018
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The random number generation API,
dsn_random64
, is tightly coupled in rdsn runtime for historical issues. As a part of the long-term plan of rdsn (see #141 ) we decoupled the RNG to make further refactoring possible.This PR also includes some unit tests.