You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.0 KiB
C++
54 lines
1.0 KiB
C++
#include <cstdio>
|
|
#include <random>
|
|
|
|
#ifdef LUA
|
|
#include <lua.hpp>
|
|
#endif
|
|
|
|
#include "udcrr.data.hpp"
|
|
|
|
template <typename T, std::size_t N>
|
|
constexpr static std::size_t ArrayLen(T (&)[N]) noexcept { return N; }
|
|
|
|
static std::random_device rd;
|
|
static std::uint32_t Rand(std::uint32_t max) noexcept
|
|
{
|
|
std::uniform_int_distribution<std::uint32_t> dist(0, max-1);
|
|
return dist(rd);
|
|
}
|
|
|
|
static void gen_id(char* buf, std::size_t len)
|
|
{
|
|
auto adv = ADVERBS[Rand(ArrayLen(ADVERBS))];
|
|
auto adj = ADJECTIVES[Rand(ArrayLen(ADJECTIVES))];
|
|
auto noun = NOUNS[Rand(ArrayLen(NOUNS))];
|
|
auto verb = VERBS[Rand(ArrayLen(VERBS))];
|
|
auto num = Rand(10000);
|
|
|
|
std::snprintf(buf, len, "%s-%s-%s-%s-%04d", adv, adj, noun, verb, num);
|
|
};
|
|
|
|
#ifdef LUA
|
|
static int lua_gen_id(lua_State* vm)
|
|
{
|
|
char buf[256];
|
|
gen_id(buf, 256);
|
|
lua_pushstring(vm, buf);
|
|
return 1;
|
|
}
|
|
|
|
extern "C" int luaopen_id_gen(lua_State* vm)
|
|
{
|
|
lua_pushcfunction(vm, lua_gen_id);
|
|
return 1;
|
|
}
|
|
#else
|
|
int main()
|
|
{
|
|
char buf[256];
|
|
gen_id(buf, 256);
|
|
puts(buf);
|
|
return 0;
|
|
}
|
|
#endif
|