Re: srand function Programming Software Development by Narue …url] will give you an idea of how rand and srand work together, but the simple answer is that you …should call srand once: [code=c] #include <stdio.h> #include … + rand() % 10; } int main ( void ) { int i; /* Call srand only once */ srand ( (unsigned)time ( NULL ) ); for ( i = 0; i < 10… sRand() Programming Software Development by crapgarden … what the < > operators are doing? [CODE]srand(static_cast<unsigned int>(time(0))); [/CODE] I realize… an unsigned int, but why not do this: [CODE]srand(unsigned int = time(0));[/CODE] I realize my questions…;ctime> using namespace std; int main() { //Roll 1 srand(static_cast<unsigned int>(time(0))); //seed random number… Re: sRand() Programming Software Development by crapgarden … <ctime> using namespace std; int main() { //Roll 1 srand(static_cast<unsigned int>(time(0))); //seed random number… a " << die << endl; //Roll 2 srand(static_cast<unsigned int>(time(0))); //seed random number… Re: sRand() Programming Software Development by pseudorandom21 Oh sorry, I didn't know you were calling srand() every time you wanted a new random number. call srand() once for the life of the program. srand and while() problem Programming Software Development by h3llpunk … res=a+b; return(res); } int main() { srand((unsigned)time(0)); for (int i=0 ;i<… random_integer = (rand()%6)+1; random_integer = pcdice1; } srand((unsigned)time(0)); for (int i=0 ;i<100… random_integer = (rand()%6)+1; random_integer = humdice1; } srand((unsigned)time(0)); for (int i=0 ;i<50… Re: srand() issue Programming Software Development by Narue …time(0) returns a value of type time_t. srand takes a parameter of type unsigned int. The warning…'re doing and to shut the hell up: [code=cplusplus] srand ( (unsigned)time ( 0 ) ); [/code] But because… seed * ( UCHAR_MAX + 2U ) + p[i]; return seed; } int main() { srand ( hash_time() ); for ( int i = 0; i < 10; i++ ) std… Re: srand and while() problem Programming Software Development by vmanes Only call srand( ) one time in your program. As fast as this code … Re: srand and while() problem Programming Software Development by h3llpunk … b) { int res; res=a+b; return(res); } void game () { srand((unsigned)time(0)); cout << "Welcome to roll… Re: srand(time(NULL)) "Error: 'time'j is not a type" Programming Software Development by sfuo …can not randomly throw in a function call like srand() unless it is within one of it's own… functions. I would call srand() at the top of your main() function. [CODE]#…random; } int getPosition( int y ) { return y; } }; int main() { srand(time(0));//seed your random here. Horse test; test.advance… srand() issue Programming Software Development by QuantNeeds … would like to fix it. It is complaining about [code] srand( time(0) ); [/code] with the following error: .cpp(25) : warning… < possibleSums; i++) results[i] = sumsArray[i]; } void Dice::rollDice() { srand( time(0) ); for( int i = 0; i < 36000; ++i… Re: srand() issue Programming Software Development by QuantNeeds … real problem. time(0) returns a value of type time_t. srand takes a parameter of type unsigned int. The warning is…'re doing and to shut the hell up: [code=cplusplus] srand ( (unsigned)time ( 0 ) ); [/code] [/QUOTE] Thanks - this worked! The 100… srand trouble Programming Software Development by natd … to 1005. I think it is something to do with srand( time(NULL); but not sure what. can you help, please… roll = 0; int total1 = 0; int total2 = 0; int a; srand(time(NULL)); while (game <= 1000){ for (roll = 1; roll… Re: srand() issue Programming Software Development by mrnutty [QUOTE=TheSamwise;939520]Simply use "srand()" at the start of the program.[/QUOTE] srand() takes an argument. Re: srand trouble Programming Software Development by smurf6189 Hey I'm trying to write a program that uses srand() too, but when I call the function in my main … print out either a 1 or 2 randomly int randomVote(){ srand((unsigned)time(NULL)); int rand_num; rand_num = rand(); if (rand_num % 2… Re: srand trouble Programming Software Development by smurf6189 Hey I'm trying to write a program that uses srand() too, but when I call the function in my main … print out either a 1 or 2 randomly int randomVote(){ srand((unsigned)time(NULL)); int rand_num; rand_num = rand(); if (rand_num % 2… srand(time(NULL)) "Error: 'time'j is not a type" Programming Software Development by coolbeanbob … several things and I have tried changing the location of srand. #include <iostream.h> #include <… int position; public: Horse(); //Horse constructor??? Per UML int random; srand( time(0)); void advance(){ random = rand() % 2; cout … Re: srand(time(NULL)) "Error: 'time'j is not a type" Programming Software Development by Ancient Dragon you can not put function calls in class declaration unless they are inside inline code. Move that srand() line to main() [code] int main() { srand(time(0)); } [/code] Depending on the compiler you are using you may have to typecase time() to unsigned int instead of time_t. Srand problem Programming Software Development by fka … map[height][width]; bool way[4], border[3]; srand(time(NULL)); //[error 'srand' was not declared in this scope] for(i=0… Re: srand() issue Programming Software Development by Alex Edwards Try-- [ICODE]srand( time(NULL) );[/ICODE] Re: srand() issue Programming Software Development by Ellisande When I did my RNG for my RPG, I had to do [code]void initialSeed(){ srand((unsigned)time(0));}[/code] Re: srand() issue Programming Software Development by Alex Edwards Odd, I can use time without ctime, which is why I gave the OP the suggestions. Here's my example-- [code=c++] #include <iostream> using namespace std; int main(){ srand(time(NULL)); cout << rand() << endl; cin.get(); return 0; } [/code] Works fine. Re: srand trouble Programming Software Development by Narue >I think it is something to do with srand( time(NULL); Nope, your logic is just wrong if you want game to end at exactly 1001. Notice how you don't check that condition every time game is incremented. You only check the condition after the inner loop has terminated. game could be incremented several times in the inner loop. Re: srand() issue Programming Software Development by TheSamwise Simply use "srand()" at the start of the program. Re: Srand problem Programming Software Development by WaltP Put the [iCODE]srand()[/iCODE] functionn call back in [iCODE]main()[/iCODE]. And where's the header that define the random functions? Re: Srand problem Programming Software Development by mrnutty [I]srand [/I]is in [I]cstdlib[/I]. So try to include cstdlib. srand function Programming Software Development by emilio hi everyone i would like to fill an array with random numbers i know i can use the next line srand( time(NULL) ); return 1 + rand() % 10 ; but the problem is that it fills my array with only one number what can i do ? Srand question Programming Software Development by Black Magic Hey, I have noticed when you use srand or rand you write: [CODE=C++]rand() % 99 + 1[/CODE] I was wondering about the 1, is it just tradition to use it or is it from 1-99? Just because i was wondering how i could make it between say 20 and 40 etc Re: Srand question Programming Software Development by twomers A solution to what you desire is given pretty much straight away, but it makes an interesting read -- [url]http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx[/url] It's not, however, a question about srand. That merely 'seeds' rand. You want to get random numbers which is rand. Re: srand function Programming Software Development by mayur.sarode thanks..the srand seeding concept works! Srand problem in tic tac toe Programming Software Development by tanmay.majumdar2 …'}; void box(); void player1_won(); void player2_won(); void fu(); int main() { srand((unsigned)time(NULL)); int abcd[45]; char type[34]; string…