Advertisement

The #include file for randomness

Started by June 08, 2002 09:44 PM
5 comments, last by Anidem 22 years, 6 months ago
Can anyone tell me the include file for using the rand and srand functions?
stdlib.h
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
That was really quick thanks
#include <stdlib.h>
#include <time.h>
...
srand((unsigned int)time(0));
...
int RandBetweenOneAndTen = (rand()/(double)RAND_MAX)*10+1;

[twitter]warrenm[/twitter]

Cool, thanks. But can someone also help with this code:
There''s a parse error on line 29 before ''return''

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

int const MAXIMUM_VALUE = 70;

int StarAt (int nGalaxy, int nX, int nY)
{
int x, y, nReturn;

srand (nGalaxy);
for (y = 0; y <= nY; y++)
{
for (x = 0; x < nX; x++)
{
nReturn = rand() % MAXIMUM_VALUE;
}
}
}
return nReturn; //line 19
}

int main()
{

return 0;
}
You have 3

{

but you also have 4

}
.

Get rid of the last { before line 19 and you should be set. Your compiler is currently reading line 19 as outside of any function which is why it''s so confused.
Advertisement
thanks, i guess i posted after u,

[edited by - Anidem on June 8, 2002 11:08:17 PM]

This topic is closed to new replies.

Advertisement