Answers for "seed random c++"

C++
1

seed random c++

#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
	int random = rand();
	/* No srand() calls before rand(), so seed = 1*/
	cout << "Seed = 1, Random number = " << random << endl;

	srand(5);
	/* Seed = 5 */
	random = rand();
	cout << "Seed = 5, Random number = " << random << endl;

	return 0;
}
Posted by: Guest on March-14-2021

Browse Popular Code Answers by Language