• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ random_string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中random_string函数的典型用法代码示例。如果您正苦于以下问题:C++ random_string函数的具体用法?C++ random_string怎么用?C++ random_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了random_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:dassencio,项目名称:cracking-the-coding-interview,代码行数:28,代码来源:solve.cpp


示例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;
}
开发者ID:dassencio,项目名称:cracking-the-coding-interview,代码行数:26,代码来源:solve.cpp


示例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);
}
开发者ID:zfletch,项目名称:zhash-c,代码行数:33,代码来源:zhash_test.c


示例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]);
      }
    }
  }
}
开发者ID:SuprDewd,项目名称:CompetitiveProgramming,代码行数:32,代码来源:aho_corasick.test.cpp


示例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);
}
开发者ID:Zodiac-Evil,项目名称:rtpengine,代码行数:7,代码来源:ice.c


示例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;
}
开发者ID:RapidStash,项目名称:RapidStash,代码行数:30,代码来源:TestConcurrentReadWrite.cpp


示例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;
	}
}
开发者ID:ThePhD,项目名称:lua-bench,代码行数:26,代码来源:string_generation.hpp


示例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 );
}
开发者ID:iamscottmoyers,项目名称:hashmap,代码行数:27,代码来源:main.c


示例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;
    }
  }
}
开发者ID:noeljt,项目名称:DataStructures,代码行数:36,代码来源:performance.cpp


示例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) );
    }
}
开发者ID:jbrezmorf,项目名称:flow123d,代码行数:18,代码来源:profiler_test.cpp


示例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) );
    }
}
开发者ID:jstebel,项目名称:flow123d,代码行数:18,代码来源:profiler_test.cpp


示例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));
}
开发者ID:50wu,项目名称:gpdb,代码行数:57,代码来源:random.c


示例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;
}
开发者ID:valhallasw,项目名称:son-of-gridengine,代码行数:56,代码来源:test_cull_hash.c


示例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 ("");
}
开发者ID:Elytum,项目名称:PISCINE_CPP,代码行数:19,代码来源:ClapTrap.cpp


示例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
    }
}
开发者ID:ShmuelLevine,项目名称:hpx,代码行数:13,代码来源:sort_tests.hpp


示例16: start

atable_ptr_t TableGenerator::string_random_delta(size_t rows, size_t cols, int string_length) {
  start(rows, cols, rows * cols);
  srand(clock());


  atable_ptr_t new_table = create_empty_table(rows, cols);


  for (size_t col = 0; col < cols; ++col) {
    std::set<std::string> values;

    for (size_t row = 0; row < rows; ++row) {
      values.insert(random_string(string_length));
      increment();
    }

    // shuffle the dict (its a delta)
    std::vector<std::string> values_vector(values.begin(), values.end());
    random_shuffle(values_vector.begin(), values_vector.end());

    OrderIndifferentDictionary<std::string> *dict = new OrderIndifferentDictionary<std::string>();
for (const auto & i: values_vector) {
      dict->addValue(i);
    }
    new_table->setDictionaryAt(AbstractTable::SharedDictionaryPtr(dict), col);

  }

  new_table->resize(rows);

  for (size_t col = 0; col < cols; ++col) {
    // shuffle the values
    std::vector<value_id_t> attribute_vector;

    for (size_t row = 0; row < rows; ++row) {
      attribute_vector.push_back(row % new_table->dictionaryAt(col)->size());
    }

    random_shuffle(attribute_vector.begin(), attribute_vector.end());

    for (size_t row = 0; row < rows; ++row) {
      ValueId v;
      v.valueId = attribute_vector[row];
      v.table = 0;
      new_table->setValueId(col, row, v);
    }
  }

  if (!_quiet) {
    std::cout << std::endl;
  }

  return new_table;
}
开发者ID:martinfaust,项目名称:hyrise,代码行数:54,代码来源:TableGenerator.cpp


示例17: TestUnlink

int TestUnlink(STORAGE::Filesystem *fs) {
	File &first = fs->select("FirstFile");
	File &second = fs->select("SecondFile");

	std::string f1Data = random_string(128);
	auto f1Writer = fs->getSafeWriter(first);
	f1Writer.write(f1Data.c_str(), f1Data.size());

	std::string f2Data = random_string(32);
	auto f2Writer = fs->getSafeWriter(second);
	f2Writer.write(f2Data.c_str(), f2Data.size());

	STORAGE::FileHeader h1 = fs->getHeader(first);
	STORAGE::FileHeader h2 = fs->getHeader(second);
	FileSize sizeBefore = h2.virtualSize;
	bool merged = fs->unlink(first);
	h2 = fs->getHeader(second);
	if (merged && h2.virtualSize != sizeBefore + STORAGE::FileHeader::SIZE + h1.virtualSize) {
		return 1;
	}
	return 0;
}
开发者ID:RapidStash,项目名称:RapidStash,代码行数:22,代码来源:TestUnlink.cpp


示例18: env

restricted_env::restricted_env(const std::shared_ptr<judge::pool> &pool,
	const string &username, const string &password)
	: env(pool)
	, username_(username)
	, session_(username, password)
	, desktop_(random_string(desktop_name_length))
{
	vector<char> sid = session_.sid();
	window_station_.remove_ace_by_sid(sid);
	window_station_.add_allowed_ace(sid, user_object::allowed_ace(0,
		GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE));
	desktop_.add_allowed_ace(sid, user_object::allowed_ace(0,
		GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE));
}
开发者ID:hiwang123,项目名称:winjudge,代码行数:14,代码来源:env.cpp


示例19: random_between_string

 std::string random_between_string(const std::string& min, const std::string& max)
 {
     if (min == max)
     {
         return min;
     }
     std::string random_key;
     for (uint32 i = 0; i < min.size() && i < max.size(); i++)
     {
         if (min[i] < max[i])
         {
             if (min[i] == max[i] - 1)
             {
                 random_key.push_back(min[i]);
                 for (uint32 j = i + 1; j < min.size(); j++)
                 {
                     if (min[j] == 127)
                     {
                         random_key.push_back(min[j]);
                     }
                     else
                     {
                         char c = (char) random_between_int32(min[j], 127);
                         random_key.push_back(c);
                         if (c > min[j])
                         {
                             break;
                         }
                     }
                 }
             }
             else
             {
                 char c = (char) random_between_int32(min[i], max[i]);
                 while (c == min[i] || c == max[i])
                 {
                     c = (char) random_between_int32(min[i], max[i]);
                 }
                 random_key.push_back(c);
             }
             break;
         }
         else
         {
             random_key.push_back(min[i]);
         }
     }
     random_key.append(random_string(5));
     return random_key;
 }
开发者ID:mrkeng,项目名称:ardb,代码行数:50,代码来源:string_helper.cpp


示例20: random_string

  std::string ValueGenerator::generate_random_string( int min, int max )
  {
    std::string random_string( "\"" );

    int size = rand() % ( max-min ) + min;

    for( int i = 0; i < size; i++ )
    {
      random_string += alphanum[ rand() % ( alphanum.size()-1 ) ];
    }

    random_string.insert( random_string.end(), '\"' );

    return random_string;
  }
开发者ID:Scarefault,项目名称:scarefault,代码行数:15,代码来源:ValueGenerator.cpp



注:本文中的random_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ randombytes函数代码示例发布时间:2022-05-30
下一篇:
C++ random_seed函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap