Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

randomize() in Visual Studio 6.0

Status
Not open for further replies.

RSTR

Programmer
Mar 25, 2000
27
US
I am having some trouble using randomize.

I believe that the function is located in stdlib.h

In turbo c++, I have this written:

#include <iostream.h>
#include <stdlib.h>

int main()
{
int x;
randomize();
x = random (100);
cout << x;
return 0;
}

This works fine in Turbo C++, but when I put the same code in Microsoft Visual C++, I get an &quot;undeclared identifier&quot; error on the two functions. Could someone please explain this to me?
-RSTR
benthecat@hotmail.com

 
if you want a number between 1 & 100 use:

x = (1 + rand() % 100)

you should read more about this because if you are running this routine multiple time you will need to seed the random number generator using srand() so that you don't receive the same set of values everytime. You can seed it by using the clock

#include <time.h>
srand( (unsigned)time( NULL ) );

HTH,
JC
 
You have to use srand(unsigned int) to start random

and &quot;rand ()&quot; to get values...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top