Random numbers in DJGPP(C++)?

Hi,

How the generate a random number so that everytime

I run the program there comes a different number?

Please tell me the style or write the code. Thanks.


Beginner


Comments

  • : Hi,

    : How the generate a random number so that everytime

    : I run the program there comes a different number?

    : Please tell me the style or write the code. Thanks.


    : Beginner



    If you do this, it may make debugging more difficult, since the program won't behave the same way twice. However:


    srand( (unsigned)time( NULL ) );


    That will seed the standard random number generator with your system time. Do this once only, as your program starts up.


    Then, you can call rand() to return to you a new random number between 0 and RAND_MAX.




Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories