mirror of
https://github.com/matrix-construct/construct
synced 2024-06-11 14:38:57 +02:00
ircd::rand: Add fill(mutable_buffer) to interface.
This commit is contained in:
parent
767322dc37
commit
e69ad0b49a
|
@ -37,6 +37,9 @@ namespace ircd::rand
|
|||
|
||||
// Random string from dictionary, fills buffer
|
||||
string_view string(const mutable_buffer &out, const std::string &dict);
|
||||
|
||||
// Random fill of buffer
|
||||
const_buffer fill(const mutable_buffer &out);
|
||||
}
|
||||
|
||||
/// Random character from dictionary
|
||||
|
|
23
ircd/rand.cc
23
ircd/rand.cc
|
@ -44,6 +44,29 @@ decltype(ircd::rand::dict::numeric) ircd::rand::dict::numeric
|
|||
"0123456789"
|
||||
};
|
||||
|
||||
ircd::const_buffer
|
||||
ircd::rand::fill(const mutable_buffer &out)
|
||||
{
|
||||
uint64_t *const __restrict__ val
|
||||
{
|
||||
reinterpret_cast<uint64_t *>(data(out))
|
||||
};
|
||||
|
||||
constexpr size_t word_size
|
||||
{
|
||||
sizeof(*val)
|
||||
};
|
||||
|
||||
size_t i(0);
|
||||
for(; i < size(out) / word_size; ++i)
|
||||
val[i] = integer();
|
||||
|
||||
for(size_t j(i * word_size); j < size(out) % word_size; ++j)
|
||||
out[j] = integer();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::rand::string(const mutable_buffer &out,
|
||||
const std::string &dict)
|
||||
|
|
Loading…
Reference in a new issue