本文整理汇总了C++中random_string函数的典型用法代码示例。如果您正苦于以下问题:C++ random_string函数的具体用法?C++ random_string怎么用?C++ random_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
for (size_t n = 0; n <= 20; ++n)
{
for (int i = 0; i < 1000; ++i)
{
std::string str = random_string(n);
suffix_tree S(str);
for (const std::string& substr : substrings(str))
{
assert(S.find(substr) == find_occurrences(substr, str));
}
/* search for random strings in str */
for (size_t m = 0; m <= n; ++m)
{
std::string rnd_str = random_string(m);
assert(S.find(rnd_str) == find_occurrences(rnd_str, str));
}
}
std::cout << "passed random tests for strings of length " << n << std::endl;
}
return 0;
}
示例2: main
int main()
{
std::random_device device;
std::mt19937 generator(device());
for (size_t n = 0; n <= 100; ++n)
{
for (int i = 0; i < 1000; ++i)
{
std::string str1 = random_string(n);
std::string str2 = random_string(n);
assert(is_anagram_1(str1, str2) == is_anagram_2(str1, str2));
std::string str1_shuf = str1;
std::shuffle(str1_shuf.begin(), str1_shuf.end(), generator);
assert(is_anagram_1(str1, str1_shuf) == true);
assert(is_anagram_2(str1, str1_shuf) == true);
}
std::cout << "passed random tests for strings of length " << n << std::endl;
}
return 0;
}
示例3: zhash_set_test
static void zhash_set_test()
{
size_t size, ii;
char **keys, **vals;
struct ZHashTable *hash_table;
size = 100;
hash_table = zcreate_hash_table();
keys = malloc(size * sizeof(char *));
vals = malloc(size * sizeof(char *));
for (ii = 0; ii < size; ii++) {
keys[ii] = random_string();
vals[ii] = random_string();
zhash_set(hash_table, keys[ii], (void *) vals[ii]);
}
assert(hash_table->size_index == 2);
assert(hash_table->entry_count == size);
for (ii = 0; ii < size; ii++) {
assert(strcmp(zhash_get(hash_table, keys[ii]), vals[ii]) == 0);
}
for (ii = 0; ii < size; ii++) {
free(keys[ii]);
free(vals[ii]);
}
free(keys);
free(vals);
zfree_hash_table(hash_table);
}
示例4: test
void test() {
/* Field testing: Kattis stringmultimatching, Codeforces 366C */
int ts = 100,
ts2 = 10;
for (int t = 0; t < ts; t++) {
int n = rand() % 1000;
vector<string> kws;
for (int i = 0; i < n; i++) {
kws.push_back(random_string(rand() % 10 + 1, rand() % 5 + 1));
}
aho_corasick ac(kws);
aho_corasick_slow ac2(kws);
for (int p = 0; p < ts2; p++) {
string s = random_string(rand() % 100, rand() % 5 + 1);
vector<string> res = ac.search(s);
vector<string> res2 = ac2.search(s);
sort(res.begin(), res.end());
sort(res2.begin(), res2.end());
assert_equal(size(res2), size(res));
for (int i = 0; i < size(res); i++) {
assert_equal(res2[i], res[i]);
}
}
}
}
示例5: __new_stun_transaction
static void __new_stun_transaction(struct ice_candidate_pair *pair) {
struct ice_agent *ag = pair->agent;
g_hash_table_remove(ag->transaction_hash, pair->stun_transaction);
random_string((void *) pair->stun_transaction, sizeof(pair->stun_transaction));
g_hash_table_insert(ag->transaction_hash, pair->stun_transaction, pair);
}
示例6: TestConcurrentReadWrite
int TestConcurrentReadWrite(STORAGE::Filesystem *fs) {
for (int i = 0; i < numWriters; ++i) {
std::srand((unsigned int)std::time(NULL) + i);
data[i] = random_string(dataSize);
}
THREADING::ThreadPool pool(numThreads);
std::thread writeThread([&pool, fs] {
for (int i = 0; i < numWriters; ++i) {
pool.enqueue([fs, i] {startWriter(fs, i); });
}
});
std::thread readThread([&pool, fs] {
for (int i = 0; i < numReaders; ++i) {
std::future<bool> ret = pool.enqueue([fs] {return startReader(fs); });
if (!ret.get()) {
failure = true;
break;
}
}
});
readThread.join();
writeThread.join();
return failure;
}
示例7: generate_random_strings
void generate_random_strings(std::size_t n, OutIt it)
{
static const std::vector<char> ch_set = {
'0','1','2','3','4',
'5','6','7','8','9',
'A','B','C','D','E','F',
'G','H','I','J','K',
'L','M','N','O','P',
'Q','R','S','T','U',
'V','W','X','Y','Z',
'a','b','c','d','e','f',
'g','h','i','j','k',
'l','m','n','o','p',
'q','r','s','t','u',
'v','w','x','y','z',
'_'
};
std::uniform_int_distribution<std::size_t> dist(0, ch_set.size() - 1);
std::uniform_int_distribution<std::size_t> lengthdist(4, 10);
auto genchar = [&dist]() { return ch_set[dist(benchmark_rng_engine())]; };
for (std::size_t i = 0; i < n; ++i) {
auto len = lengthdist(benchmark_rng_engine());
*it = std::pair<std::string, std::size_t>(random_string(len, genchar), i);
++it;
}
}
示例8: random_insertions
static void random_insertions( void )
{
int res;
hashmap_t hashmap;
unsigned int i;
res = hashmap_init_with_buckets( &hashmap, 8192 /* pow 2 */ );
assert( 0 == res );
for( i = 0; i < 100000; ++i )
{
char str[10];
hashmap_value_t val = rand();
hashmap_value_t retrieved;
random_string( str, sizeof(str) );
res = hashmap_insert( &hashmap, str, val );
assert( 0 == res );
res = hashmap_find( &hashmap, str, &retrieved );
assert( 1 == res );
assert( retrieved == val );
}
hashmap_term( &hashmap );
}
示例9: load_data
// Load the data either from a file, or generate random data
void load_data(const std::string &input, std::string*& input_data, int& input_count, int string_length) {
if (input == "random") {
// seed the random number generator
// using a fixed seed for repeatable tests for debugging
srand(37);
// using the time as a seed
//srand(time(0));
input_data = new std::string[input_count];
for (int i = 0; i < input_count; i++)
input_data[i] = random_string(string_length);
} else {
// load the file once to get the count
std::ifstream istr(input.c_str());
if (!istr) {
std::cerr << "Error: Can't open input file: " << input << std::endl;
exit(0);
}
std::string s;
input_count = 0;
while (istr >> s) {
input_count++;
}
// make an array exactly the right size
input_data = new std::string[input_count];
// close & reopen & reread the file to store the data
istr.close();
istr.open(input.c_str());
for (int i = 0; i < input_count; i++) {
istr >> s;
input_data[i] = s;
}
}
}
示例10: EXPECT_EQ
void ProfilerTest::test_str_hash() {
EXPECT_EQ(0, str_hash("", PROFILER_HASH_DEFAULT));
EXPECT_EQ(65, str_hash("A", PROFILER_HASH_DEFAULT));
EXPECT_EQ(6597, str_hash(" A", PROFILER_HASH_DEFAULT));
srand ( time(NULL) );
char a[16];
char b[16];
// random test for hash collision
unsigned int n_pairs=100;
for(unsigned int i=0; i<n_pairs; i++) {
random_string(a);
random_string(b);
if (string(a) != string(b) )
EXPECT_NE( str_hash(a, PROFILER_HASH_DEFAULT) , str_hash(b, PROFILER_HASH_DEFAULT) );
}
}
示例11: TEST
TEST(Profiler, str_hash) {
EXPECT_EQ(0, str_hash(""));
EXPECT_EQ(65, str_hash("A"));
EXPECT_EQ(6597, str_hash(" A"));
srand ( time(NULL) );
char a[16];
char b[16];
// random test for hash collision
unsigned int n_pairs=100;
for(unsigned int i=0; i<n_pairs; i++) {
random_string(a);
random_string(b);
if (string(a) != string(b) )
EXPECT_NE( str_hash(a) , str_hash(b) );
}
}
示例12: dbms_random_string
Datum
dbms_random_string(PG_FUNCTION_ARGS)
{
char *option;
int len;
const char *charset;
int chrset_size;
const char *alpha_mixed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char *lower_only = "abcdefghijklmnopqrstuvwxyz";
const char *upper_only = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char *upper_alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const char *printable = "`1234567890-=qwertyuiop[]asdfghjkl;'zxcvbnm,./[email protected]#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVVBNM<>? ";
option = text_to_cstring(PG_GETARG_TEXT_P(0));
len = PG_GETARG_INT32(1);
switch (option[0])
{
case 'a':
case 'A':
charset = alpha_mixed;
chrset_size = strlen(alpha_mixed);
break;
case 'l':
case 'L':
charset = lower_only;
chrset_size = strlen(lower_only);
break;
case 'u':
case 'U':
charset = upper_only;
chrset_size = strlen(upper_only);
break;
case 'x':
case 'X':
charset = upper_alphanum;
chrset_size = strlen(upper_alphanum);
break;
case 'p':
case 'P':
charset = printable;
chrset_size = strlen(printable);
break;
default:
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("unknown option '%s'", option),
errhint("available option \"aAlLuUxXpP\"")));
/* be compiler a quiete */
charset = NULL;
chrset_size = 0;
}
PG_RETURN_TEXT_P(random_string(charset, chrset_size, len));
}
示例13: main
int main(int argc, char *argv[])
{
int num_objects;
int num_names;
int i;
bool uh, nuh;
if (argc != 1 && argc < 5) {
usage(argv[0]);
}
/* initialize globals */
lInit(my_nmv);
clk_tck = sysconf(_SC_CLK_TCK); /* JG: TODO: sge_sysconf? */
prof_mt_init();
/* we need random numbers */
srand(time(0));
if (argc == 1) {
num_objects = 1000;
num_names = 10;
uh = true;
nuh = true;
} else {
/* parse commandline options */
num_objects = atoi(argv[1]);
num_names = atoi(argv[2]);
uh = atoi(argv[3]) == 0 ? false : true;
nuh = atoi(argv[4]) == 0 ? false : true;
}
/* create name array */
names = sge_malloc (num_names * sizeof(const char *));
/* build random names */
for (i = 0; i < num_names; i++) {
const char *name = random_string(10);
names[i] = name;
}
/* output header */
printf(HEADER_FORMAT, "uh ", "nuh",
"create", "copy", "rau", "inu", "curo", "cnuro",
"dru", "(objs)", "dinu", "(objs)", "mem(kB)");
/* do tests */
do_test(uh, nuh, num_objects, num_names);
/* free names */
for (i = 0; i < num_names; i++) {
sge_free(&(names[i]));
}
return EXIT_SUCCESS;
}
示例14: talk_fn
std::string talk_fn ( std::string const & kind ) {
static const char *character_selection[] = CHARACTER_SELECTION_QUOTES;
static const char *melee[] = MELEE_QUOTES;
static const char *ranged[] = RANGED_QUOTES;
static const char *healing[] = HEALING_QUOTES;
static const char *death[] = DEATH_QUOTES;
if (kind == "creation")
return (random_string(character_selection, ARRAY_SIZE(character_selection)));
else if (kind == "melee")
return (random_string(melee, ARRAY_SIZE(melee)));
else if (kind == "ranged")
return (random_string(ranged, ARRAY_SIZE(ranged)));
else if (kind == "healing")
return (random_string(healing, ARRAY_SIZE(ranged)));
else if (kind == "death")
return (random_string(death, ARRAY_SIZE(death)));
return ("");
}
示例15: rnd_strings
// --------------------------------------------------------------------
// fill a vector with random strings
void rnd_strings(std::vector<std::string> &V)
{
const std::size_t test_size = HPX_SORT_TEST_SIZE_STRINGS;
// Fill vector with random strings
V.clear();
V.reserve(test_size);
// random strings up to 128 chars long
for (std::size_t i=0; i<test_size; i++) {
V.push_back(random_string( std::rand() % 128)); //-V106
}
}