Question about pseudo random numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hmlewis
    New Member
    • Oct 2008
    • 1

    Question about pseudo random numbers

    I have a program that allows a user to guess a number 5 times. How can I create the number using a pseudo random number rather than "pre-defining" the numbers. The number has to be between 1 and 20??

    Any help would be greatly appreciated.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Have a look at the srand() and rand() functions; they're part of the standard library.

    kind regards,

    Jos

    Comment

    • curiously enough
      New Member
      • Aug 2008
      • 79

      #3
      #include<stdlib .h>//contains random functions and RAND_MAX
      #include<time.h >//contains time
      srand(time(0));
      number=rand()%2 0+1;

      You know, you don't have to post this question here and wait till(or if) someone answers it, you can just google it.

      Comment

      Working...