Thread: Random Number

  1. #1
    Registered User
    Join Date
    Feb 2006

    Random Number

    How can I make a function, or if there is already a function that will return a different random number each time I use it.

    Like rand(1,10); will return a random number 1-10.

    And if I start up the program again, or use the function again it won't return the same number.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Check the FAQ all the way down at the bottom under the heading Prelude's corner.

  3. #3
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Umeň, Sweden
    #include <stdlib.h>
    #include <time.h>
    int randnum (int start, int end)
        static bool notseeded = true;
        if (notseeded) {
            notseeded = false;
        return rand()%(end-start+1) + start;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rapid random number generation problem
    By Newton in forum C Programming
    Replies: 17
    Last Post: 09-19-2008, 02:08 PM
  2. Random number in range generation.
    By hebali in forum C Programming
    Replies: 19
    Last Post: 03-04-2008, 10:46 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. random number tutorial
    By 7stud in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2005, 02:41 PM
  5. Random Number Generator
    By Ikurik in forum C++ Programming
    Replies: 16
    Last Post: 08-17-2003, 07:34 PM