CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2008
    Posts
    20

    Question C languege (auto ganerate number)

    How to use C languege to auto generate number???
    example:
    1001
    1002
    than 1st number is fit(1002)

    by not using this matter:

    Code:
    int id=101;
    .........
    id++;
    pls help!!!

  2. #2
    Join Date
    Dec 2008
    Posts
    144

    Re: C languege (auto ganerate number)

    When you say "auto-generate" I think of random numbers, but it looks like you're talking about incrementing numbers. Can you be a little more specific on exactly what you want?

  3. #3
    Join Date
    Nov 2008
    Posts
    20

    Re: C languege (auto ganerate number)

    Quote Originally Posted by CreganTur View Post
    When you say "auto-generate" I think of random numbers, but it looks like you're talking about incrementing numbers. Can you be a little more specific on exactly what you want?
    yayaya thx
    can you tech me how to write the "random numbers" segment
    example???
    yes i wan that "random pick number"!!!

  4. #4
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: C languege (auto ganerate number)

    yes i wan that "random pick number"!!!
    Take a look at srand and rand.

  5. #5
    Join Date
    Oct 2008
    Posts
    116

    Re: C languege (auto ganerate number)

    Absolutely, I don't think that I understand what you said all.

    Due to my understand It's my answer:

    You can use a large number begin with 1
    ex: id = 1000;
    And after that you can general other number so that it's less than id
    ex: id2 = rand()%id;
    And finally you can sum both of them
    ex: result = id + id2;
    My English is very bad. So tell me if Something I talked make u confuse.
    My Ebook Store: www.coding.vn/book.php

  6. #6
    Join Date
    Nov 2008
    Posts
    20

    Smile Re: C languege (auto ganerate number)

    Quote Originally Posted by Skizmo View Post
    Take a look at srand and rand.
    thx i know ald
    Code:
    /* RAND.C: This program seeds the random-number generator
    * with the GetTickCount, then displays 10 random integers.
     */
    
    #include <stdlib.h>
    #include <stdio.h>
    #include <winbase.h>
    
    void main( void )
    {
       int i;
       /* Seed the random-number generator with GetTickCount so that
          the numbers will be different every time we run.
           */
       srand(
           GetTickCount() 
             );
       /* Display 10 numbers. */
       for(
             i = 0;   i < 10;i++ 
            )
       printf(
             "%6d\n", rand() 
            );
       }

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: C languege (auto ganerate number)

    I have no idea what language you're speaking.

  8. #8
    Join Date
    Nov 2008
    Posts
    34

    Re: C languege (auto ganerate number)

    you can also to customize generate number :

    Code:
    int 
    GetRandomNumber(int nLowNumber, int nHighNumber)
    {
      const int IMax = dwLowNumber;
      const int IMin = dwHighNumber;
      
    return (IMin + rand() % (IMax - IMin));
    }
    // Example Usage : generate number between ( 12 ... 102)
    // int randnum = GetRandomNumber ( 12, 102 ) ;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured