• 0

[c++] Random number generator


Question

4 answers to this question

Recommended Posts

  • 0

alternative way

srand(time(NULL)); // seeds random number generator, so it generates it based on time, otherwise the random numbers are usually the same each time you run the program... so ... not really that random :) 
int rand_num = rand()%10+1; // random number between 1 - 10  (+1 because it starts at 0)

for this way you need

stdlib.h

and time.h

Link to comment
Share on other sites

  • 0
alternative way

srand(time(NULL)); // seeds random number generator, so it generates it based on time, otherwise the random numbers are usually the same each time you run the program... so ... not really that random :) 
int rand_num = rand()%10+1; // random number between 1 - 10 ?(+1 because it starts at 0)

for this way you need

stdlib.h

and time.h

yeah, basically what I meant, but was too lazy to type :pp

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.