• Advertisement

Archived

This topic is now archived and is closed to further replies.

The #include file for randomness

This topic is 5740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone tell me the include file for using the rand and srand functions?

Share this post


Link to post
Share on other sites
Advertisement
#include <stdlib.h>
#include <time.h>
...
srand((unsigned int)time(0));
...
int RandBetweenOneAndTen = (rand()/(double)RAND_MAX)*10+1;

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
thanks, i guess i posted after u,

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

Share this post


Link to post
Share on other sites

  • Advertisement