Thread: How can I get random numbers from 60 to 100

  1. #1
    Unregistered
    Guest

    How can I get random numbers from 60 to 100

    Im supposed to get random numbers from 60 to 100 how can i do it. I know how to get raqndom numbers but how can i get then between 60 and 100

    a[i] = rand() is going to give me any number how can i set it
    between 60 to 100


    Thank u

    email is [email protected]

  2. #2
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    var=rand()%40;
    var+=60;


    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  3. #3
    Unregistered
    Guest
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.c>
    int main (void)
    {
    int counter = 0;
    int x;
    srand( (unsigned)time( NULL ) );

    {
    printf ("\n\t\tThis Text is Displayed in Standard color\n");
    textcolor(BLUE); /*changes text color*/

    printf ("\n\n\t\tThe Text Below is in Blue\n");
    printf ("\n\t\tTen Random Numbers within the Range will be Displayed\n");
    printf ("\n\n\n\t\tThe Program will pause for 10 Seconds\n");
    sleep(10000); /*will wait for about 10 secs before carrying on */
    textcolor (WHITE);
    printf("\n\n\t\tPress Enter/Return to Continue");
    getch();
    clrscr(); /*clears the screen, comment out to see the difference*/
    do
    {
    x = (rand() %35) + 50;/* limits rand range */
    textcolor(YELLOW); /*changes text color*/
    printf ("\t%d ",x);
    counter++;
    x=0;
    }
    while ( counter<30);/* displays 30 random numbers */
    printf ("\n\n\n\t\tThe Program will pause for 5 Seconds\n");
    sleep(5000); /*will wait for about 5 secs before carrying on */


    clrscr(); /*clears the screen, comment out to see the difference*/
    }
    textcolor(LIGHTGRAY); /*returns screen color*/
    printf ("\n\n\n\t\t\tPress Return/Enter key to Close");/* holds display untill key press */
    getch();
    return(0);
    }

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Please don't post OS specific code as an answer to a generic C question. I can't even compile your code on my OS, and I have a Borland compiler!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by red_baron
    var=rand()%40;
    var+=60;


    Actually, this is wrong. This would only give you 60 to 99.

    var = 60 + rand()%41;

    Also, just see the FAQ (original poster) for using random numbers.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    :'(
    why do i always make such little mistakes
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >why do i always make such little mistakes
    Because the little ones are the hardest to see.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. Generatin Random Numbers
    By dantu1985 in forum C Programming
    Replies: 15
    Last Post: 08-13-2007, 01:21 AM
  3. Random numbers
    By Mavix in forum C Programming
    Replies: 3
    Last Post: 05-13-2007, 09:01 AM
  4. preventing same random numbers in JAVA
    By Rumproast23 in forum Tech Board
    Replies: 10
    Last Post: 04-04-2007, 06:46 AM
  5. random numbers limit
    By HAssan in forum C Programming
    Replies: 9
    Last Post: 12-06-2005, 07:51 PM