コード例 #1
0
ファイル: async.cpp プロジェクト: MidoriYakumo/ModernCpp
int main()
{
	// Get current time using High resolution clock (C++11)
	// Count a duration with the time span between the epoch and tthe time_point (C++11)
	auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
	// A random number generator based on Mersenne Twister algorithm (C++11)
	std::mt19937 mtRand(seed);

	// Create a vector with 10000 elements
	std::vector<int> v(10000);
	// Assign a random number (1 ~ 100)
	for (auto& value : v)
		value = mtRand() % 100 + 1;

	// Print result
	std::cout << "The sum is " << parallelSum(v.begin(), v.end()) << std::endl;

	return 0;
}
コード例 #2
0
int _tmain(int argc, _TCHAR* argv[])
{
	// seed value
	auto curTime = std::chrono::system_clock::now();
	auto duration = curTime.time_since_epoch();
	auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
		

	std::mt19937 mtRand(millis);
	std::uniform_int_distribution<__int64> dist1(0, 1);

	char element[4][4];

	for (int i = 0; i < 4; ++i)
	for (int j = 0; j < 4; ++j)
		element[i][j] = '0';

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			element[i][j] = dist1(mtRand) ? '*' : element[i][j];

			if (element[i][j] == '*')
			{
				for (int i2 = i - 1; i2 < i + 1; ++i2)
				{
					for (int j2 = j - 1; j2 < j + 1; ++j2)
					{	
						if (j2 > -1 && i2 > -1)
						{
							if (element[i2][j2] != '*')
							{
								element[i2][j2] += 1;
							}
						}
					}
					
				}
			}
		}
	}

	for (int i3 = 0; i3 < 4; ++i3)
	{
		for (int j3 = 0; j3 < 4; ++j3)
		{
			std::cout << element[i3][j3];
		}
		
		std::cout << std::endl;
	}

	
	

	//for (int i = 0; i < 4; ++i)
	//{
	//	for (int k = 0; k < 4; ++k)
	//	{
	//		//element[i][k] = *std::to_string(dist1(mtRand)).c_str();
	//		//element[i][k] = dist1(mtRand) ? '*' : '.';
	//		

	//		std::cout << i << k << ' ';
	//		//std::cout << element[i][k] << ' ';
	//	}


	//	std::cout << std::endl;

	//}

	system("pause");
	
	return 0;
}