Results 1 to 3 of 3

Thread: Random Number

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522

    Random Number

    quick formula.

    I need to get a random number between a High and a low.

    what's the formula??
    It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Code:
    for(i=0;i<10;i++) printf("%d\n",rand() ); // print some random numbers

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    with [min, max] being an inclusive range
    Code:
    inline int getrandfromto(int min, int max)
    {
      return ((rand() % (max-min+1))+min);
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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