mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd::rand: Add vector convenience interface.
This commit is contained in:
parent
28887b0dc0
commit
7e7eb14e0b
2 changed files with 40 additions and 0 deletions
|
@ -32,6 +32,12 @@ namespace ircd::rand
|
|||
uint64_t integer();
|
||||
uint64_t integer(const uint64_t &min, const uint64_t &max); // inclusive
|
||||
|
||||
// Random vector
|
||||
template<class T> T vector() = delete;
|
||||
template<> u128x1 vector();
|
||||
template<> u256x1 vector();
|
||||
template<> u512x1 vector();
|
||||
|
||||
// Random character from dictionary
|
||||
char character(const std::string &dict = dict::alnum);
|
||||
|
||||
|
|
34
ircd/rand.cc
34
ircd/rand.cc
|
@ -83,3 +83,37 @@ ircd::rand::string(const mutable_buffer &out,
|
|||
|
||||
return out;
|
||||
}
|
||||
|
||||
template<>
|
||||
ircd::u512x1
|
||||
ircd::rand::vector()
|
||||
{
|
||||
return u64x8
|
||||
{
|
||||
integer(), integer(),
|
||||
integer(), integer(),
|
||||
integer(), integer(),
|
||||
integer(), integer(),
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
ircd::u256x1
|
||||
ircd::rand::vector()
|
||||
{
|
||||
return u64x4
|
||||
{
|
||||
integer(), integer(),
|
||||
integer(), integer(),
|
||||
};
|
||||
}
|
||||
|
||||
template<>
|
||||
ircd::u128x1
|
||||
ircd::rand::vector()
|
||||
{
|
||||
return u64x2
|
||||
{
|
||||
integer(), integer()
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue