| | |
Random Number
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hey, I was just wondering how to get a variable assigned a random number within a certain range. I tried the rand, but I seem to get the same set of numbers everytime I run the code...
I did some research on random numbers in C++ and understand the whole pourpose of seeding random generation, but couldn't find anywhere that just gives me an example on how to do it. Does anyone know a website that could show me what to do? Or even show me here?
Thanks everyone,
-Matt
I did some research on random numbers in C++ and understand the whole pourpose of seeding random generation, but couldn't find anywhere that just gives me an example on how to do it. Does anyone know a website that could show me what to do? Or even show me here?
Thanks everyone,
-Matt
srand() seeds the random number generator, you should call srand() one time only and near the top of main(). Most of us use the time() function as the paramter to srand()
C++ Syntax (Toggle Plain Text)
int main() { srand(time(0)); }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Random number generator's (C++)
- Need to know how to create a database that will generate a random number (Database Design)
- Random number generation (C)
- Help with random number gen (C++)
Other Threads in the C++ Forum
- Previous Thread: LNK2001 error
- Next Thread: Question???
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelp homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






