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

1. ## 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 omar_antonio25@hotmail.com

2. var=rand()%40;
var+=60;

3. #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);
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. 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!

5. 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.

6. :'(
why do i always make such little mistakes

7. >why do i always make such little mistakes
Because the little ones are the hardest to see.

-Prelude