Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

util: make rand a standalone util decoupled from rdsn runtime #163

Merged
merged 13 commits into from
Sep 24, 2018

Conversation

neverchanje
Copy link
Contributor

@neverchanje neverchanje commented Sep 20, 2018

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.

shengofsun
shengofsun previously approved these changes Sep 20, 2018
namespace dsn {
namespace rand {

// uint64n returns, as an uint64_t, a non-negative pseudo-random number in [min, max].
Copy link
Contributor

Choose a reason for hiding this comment

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

注视是uint64n, 代码是uint64in。
不过这命名没看懂,n和in代表啥?

@@ -0,0 +1,21 @@
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

文件名还是统一用cpp吧

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; }
Copy link
Contributor

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不一定是

@neverchanje
Copy link
Contributor Author

neverchanje commented Sep 21, 2018

@shengofsun 之前的命名根据 golang 的 math.rand,https://golang.org/pkg/math/rand/

现在按你的批评改成更 c++ 风格的命名,另外修缮了注释,你可以看一下

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

Successfully merging this pull request may close these issues.

3 participants