Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
46ad4f89
Commit
46ad4f89
authored
May 14, 2019
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fast_rand_bytes in fast_rand.h
parent
b3469340
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
fast_rand.cpp
src/butil/fast_rand.cpp
+16
-0
fast_rand.h
src/butil/fast_rand.h
+3
-0
No files found.
src/butil/fast_rand.cpp
View file @
46ad4f89
...
...
@@ -160,4 +160,20 @@ double fast_rand_double() {
return
fast_rand_double
(
&
_tls_seed
);
}
void
fast_rand_bytes
(
void
*
output
,
size_t
output_length
)
{
const
size_t
n
=
output_length
/
8
;
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
static_cast
<
uint64_t
*>
(
output
)[
i
]
=
fast_rand
();
}
const
size_t
m
=
output_length
-
n
*
8
;
if
(
m
)
{
uint8_t
*
p
=
static_cast
<
uint8_t
*>
(
output
)
+
n
*
8
;
uint64_t
r
=
fast_rand
();
for
(
size_t
i
=
0
;
i
<
m
;
++
i
)
{
p
[
i
]
=
(
r
&
0xFF
);
r
=
(
r
>>
8
);
}
}
}
}
// namespace butil
src/butil/fast_rand.h
View file @
46ad4f89
...
...
@@ -63,6 +63,9 @@ template <typename T> T fast_rand_in(T min, T max) {
// Cost: ~15ns
double
fast_rand_double
();
// Fills |output_length| bytes of |output| with random data.
void
fast_rand_bytes
(
void
*
output
,
size_t
output_length
,
uint8_t
min
);
}
#endif // BUTIL_FAST_RAND_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment