mirror of
https://github.com/aimrebirth/tools.git
synced 2026-04-15 01:43:25 +00:00
Add name generator.
This commit is contained in:
parent
6a8aa716e7
commit
c268da3ea1
3 changed files with 86 additions and 3 deletions
|
|
@ -16,13 +16,13 @@ if (MSVC)
|
||||||
set(disable_msvc_warnings "/W1 /wd4996")
|
set(disable_msvc_warnings "/W1 /wd4996")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP ${disable_msvc_warnings}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP ${disable_msvc_warnings}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP ${disable_msvc_warnings}")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP ${disable_msvc_warnings}")
|
||||||
|
|
||||||
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
|
|
||||||
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
|
|
||||||
else()
|
else()
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14")
|
||||||
endif(MSVC)
|
endif(MSVC)
|
||||||
|
|
||||||
|
add_definitions(-DPOLYGON4_TOOLS=1)
|
||||||
|
add_definitions(-DPOLYGON4_STATIC=1)
|
||||||
|
|
||||||
if (NOT DATABASE_MANAGER_DIR)
|
if (NOT DATABASE_MANAGER_DIR)
|
||||||
message(STATUS "DATABASE_MANAGER_DIR variable is not set! Some targets won't be built")
|
message(STATUS "DATABASE_MANAGER_DIR variable is not set! Some targets won't be built")
|
||||||
else()
|
else()
|
||||||
|
|
|
||||||
|
|
@ -34,4 +34,7 @@ file(GLOB tm_converter_src "tm_converter/*")
|
||||||
add_executable(tm_converter ${tm_converter_src})
|
add_executable(tm_converter ${tm_converter_src})
|
||||||
target_link_libraries(tm_converter common)
|
target_link_libraries(tm_converter common)
|
||||||
|
|
||||||
|
file(GLOB name_generator_src "name_generator/*")
|
||||||
|
add_executable(name_generator ${name_generator_src})
|
||||||
|
|
||||||
add_subdirectory(common)
|
add_subdirectory(common)
|
||||||
80
src/name_generator/name_generator.cpp
Normal file
80
src/name_generator/name_generator.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* AIM name_generator
|
||||||
|
* Copyright (C) 2015 lzwdgc
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <random>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class NameGenerator
|
||||||
|
{
|
||||||
|
static const int letmin = 2;
|
||||||
|
static const int letmax = 3;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NameGenerator()
|
||||||
|
: rng(std::random_device()())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string generate(int sylmin = 2, int sylmax = 3)
|
||||||
|
{
|
||||||
|
static const std::string consonants = "bcdfghjklmnpqrstvwxz";
|
||||||
|
static const std::string vowels = "aeiouy";
|
||||||
|
std::uniform_int_distribution<> c_distr(0, consonants.size() - 1);
|
||||||
|
std::uniform_int_distribution<> v_distr(0, vowels.size() - 1);
|
||||||
|
std::uniform_int_distribution<> cv_distr(0, 1);
|
||||||
|
auto n_syllables = std::uniform_int_distribution<>(sylmin, sylmax)(rng);
|
||||||
|
std::uniform_int_distribution<> let_distr(letmin, letmax);
|
||||||
|
std::string name;
|
||||||
|
for (int s = 0; s < n_syllables; s++)
|
||||||
|
{
|
||||||
|
auto n_letters = let_distr(rng);
|
||||||
|
int n_consonants = 0, n_vowels = 0;
|
||||||
|
std::string syllable;
|
||||||
|
for (int l = 0; l < n_letters; l++)
|
||||||
|
{
|
||||||
|
auto vowel = cv_distr(rng);
|
||||||
|
syllable += vowel ? vowels[v_distr(rng)] : consonants[c_distr(rng)];
|
||||||
|
n_consonants += !vowel;
|
||||||
|
n_vowels += vowel;
|
||||||
|
}
|
||||||
|
if (n_consonants == n_letters)
|
||||||
|
{
|
||||||
|
auto pos = std::uniform_int_distribution<>(0, n_letters - 1)(rng);
|
||||||
|
syllable[pos] = vowels[v_distr(rng)];
|
||||||
|
}
|
||||||
|
else if (n_vowels == n_letters)
|
||||||
|
{
|
||||||
|
auto pos = std::uniform_int_distribution<>(0, n_letters - 1)(rng);
|
||||||
|
syllable[pos] = consonants[c_distr(rng)];
|
||||||
|
}
|
||||||
|
name += syllable;
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::mt19937 rng;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
NameGenerator ng;
|
||||||
|
std::cout << ng.generate();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue