Thread: Another random number ?

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    Another random number ?

    I understand how to generate random numbers. How do I make the number keep changing throughout the program or when I tell it to?
    How do you make random numbers with a range between lets say 10 and 20?

    I need help here
    to.
    My computer is awesome.

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    check this.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    How can I accomplish that without the users input? In another post someone said that I can assign random numbers new values throughout the program how? I still don't know what to do in my other post. It seems that people usually stop posting and I have a lot of unaswered questions.
    My computer is awesome.

  4. #4
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    The FAQ is your friend, sir. But sheesh, I'll tell you a nice, easy way.
    Code:
        int min, max;             //We have a minimum value, and a maximum
        min=100; max=200;        //We want a number between 100-200
        int Range= (max-min)+1;
    
    /*This will give us the number 101 for our range. 
    Why add 1? We're going to divide this using the % operator,
    which divides and returns a remainder.
    This means that our remainder can be as big as 100,
    instead of 99...so we can reach 200.*/
    
       int Num = rand()%Range+min;
    
    /*We have a random number,
    divided by our range...this number will be a remainder between 0-100.
    If you add the min to that (100),
    you produce a number between 100-200. 
    Perfecto. ^_^*/
    Also honey...you don't always have to use the two parameters for main()...I notice you use them all the time, even when you don't even refer to them at all in your program.
    Last edited by Krak; 03-06-2005 at 05:19 PM.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Quote Originally Posted by Krak
    Also honey...you don't always have to use the two parameters for main()...I notice you use them all the time, even when you don't even refer to them at all in your program.
    My compiler puts it there I don't bother with erasing it.

    Also honey
    ???
    My computer is awesome.

  6. #6
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by cerin
    ???
    I like calling people "honey, dear and sweetie". You'll just have to learn to live with it, love.

    Hey, at least I helped you out, ya know.

    And btw dear...you might want to replace those two main() parameters with 'void' to make sure you don't confuse anyone reading your code...You know....maybe someone who either doesn't know what they mean...or is confused as to why you bothered writing them in if you're not going to use them. Plus it makes your code shorter and seem a little more readable too.

    I guess it really doesn't matter...your call, guy.
    Last edited by Krak; 03-06-2005 at 06:05 PM.

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    How do I keep assigning values to a random throughout the program using time??Ya this is getting my discouraged I can't find it on google.
    I've asked this question several times in different places, but no one answers. Does anyone know how to do this?!?!
    My computer is awesome.

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