functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • molatelo
    New Member
    • Mar 2007
    • 7

    functions

    how do we use the function randomize() to initialize randomization process?
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Is randomize even a proper method. I thought it was srand and rand.

    Comment

    • willakawill
      Top Contributor
      • Oct 2006
      • 1646

      #3
      Originally posted by molatelo
      how do we use the function randomize() to initialize randomization process?
      this is from the help file in vc++
      Code:
      /* RAND.C: This program seeds the random-number generator
       * with the time, then displays 10 random integers.
       */
      
      #include <stdlib.h>
      #include <stdio.h>
      #include <time.h>
      
      int main( void )
      {
         int i;
      
         /* Seed the random-number generator with current time so that
          * the numbers will be different every time we run.
          */
         srand( (unsigned)time( NULL ) );
      
         /* Display 10 numbers. */
         for( i = 0;   i < 10;i++ )
            printf( "  %6d\n", rand() );
         return 0;
      }

      Comment

      • molatelo
        New Member
        • Mar 2007
        • 7

        #4
        Originally posted by RedSon
        Is randomize even a proper method. I thought it was srand and rand.
        Ok, so how do we use srand?

        Comment

        • molatelo
          New Member
          • Mar 2007
          • 7

          #5
          Originally posted by willakawill
          this is from the help file in vc++
          Code:
          /* RAND.C: This program seeds the random-number generator
           * with the time, then displays 10 random integers.
           */
          
          #include <stdlib.h>
          #include <stdio.h>
          #include <time.h>
          
          int main( void )
          {
             int i;
          
             /* Seed the random-number generator with current time so that
              * the numbers will be different every time we run.
              */
             srand( (unsigned)time( NULL ) );
          
             /* Display 10 numbers. */
             for( i = 0;   i < 10;i++ )
                printf( "  %6d\n", rand() );
             return 0;
          }
          Ok thanks, so why do you use function rand() in printf statement

          Comment

          • willakawill
            Top Contributor
            • Oct 2006
            • 1646

            #6
            Originally posted by molatelo
            Ok thanks, so why do you use function rand() in printf statement
            It is returning a random number. In this case the number is printed to the screen just for demonstration purposes. With code snippets like this you should copy them to your ide and compile them to see how it works. That is how I learn this stuff :)

            Comment

            • molatelo
              New Member
              • Mar 2007
              • 7

              #7
              Originally posted by willakawill
              It is returning a random number. In this case the number is printed to the screen just for demonstration purposes. With code snippets like this you should copy them to your ide and compile them to see how it works. That is how I learn this stuff :)
              Ok thanks!

              Comment

              • willakawill
                Top Contributor
                • Oct 2006
                • 1646

                #8
                You are very welcome :)

                Comment

                Working...