I have a question we are suppose to input a seed value for a randon number generator, but I am having issues with using the srand(seed), but the problem is I am getting the same output every time for the random numbers how can I do it with the user entering a seed not srand(time(null)) and get differn't random numbers.

Something like this ? Don't know why you would wan't to do this
for.

for(int i = 0 ; i < 100; i++)
	{
		cout<<"Enter a seed value : ";
		int seed = 0;
		cin >> seed;
		while(seed < 0) { cout<<"\nEnter non negative number : "; cin >> seed; }
		cout<<"\nYour random number is  : "<<rand()<<endl;
	}

I know that but how about if you are only to enter a seed number one time to initialize the integer generator rand()?

I know that but how about if you are only to enter a seed number one time to initialize the integer generator rand()?

Then put the seeding before the loop, not inside the loop:

cout<<"Enter a seed value : ";
	int seed = 0;
	cin >> seed;
	while(seed < 0) { cout<<"\nEnter non negative number : "; cin >> seed; }



	for(int i = 0 ; i < 100; i++)
	{
		cout<<"\nYour random number is  : "<<rand()<<endl;
	}

Hmm. Thought I had edited the last post. You have to actually SEED it too. Forgot that before. See red line.

cout<<"Enter a seed value : ";
	int seed = 0;
	cin >> seed;
	while(seed < 0) { cout<<"\nEnter non negative number : "; cin >> seed; }

        srand (seed);

	for(int i = 0 ; i < 100; i++)
	{
		cout<<"\nYour random number is  : "<<rand()<<endl;
	}

Oh silly rabbit, I forgot to seed the seed also.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.