Thread: Random Number Range Problem.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    10

    Random Number Range Problem.

    Hello all,
    I am trying to create a random number between a range of certain numbers, lets say 1 -10. I am using this below but for some reason it gives me the same number most of the time.

    Code:
    int rand_func(int min, int max ) 
    //this function takes 2 arguments: min and max 
    // and creates random numbers based on min an max and loads it into i
    
    {
    
    int i = 0;
    i = rand(); 
    
    printf("\t%d", i);
    
    i = min + (max - min) * i / RAND_MAX; // min and max forumula
    printf("\t%d\n",i);
    
    
    
    
    
    
      return i;
    
    }
    I appreciate any response. Thank You!
    Last edited by xamlit; 01-21-2006 at 12:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random number gen & looping probelm :?
    By FoxeySoulSLayer in forum C++ Programming
    Replies: 1
    Last Post: 04-10-2009, 05:44 PM
  2. Help regarding random number
    By Bargi in forum C Programming
    Replies: 6
    Last Post: 03-11-2009, 01:16 PM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  4. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM