The rand function in c or function rand() in c is used to generate random numbers between 0 and rand_max. Rand_max is a constant and is equal to the maximum value returned by the rand() function. The default value of rand_max may vary.
Program Description: c program to generate random numbers in c within a range.
#include #include int main() { int limit,random_number,i; printf("Enter the limit:"); scanf("%d",&limit); printf("Random Numbers in the given Limit:\n"); for (i = 1; i <= limit; i++) { random_number = rand() % 100 + 1; printf("%d\n", random_number); } return 0; } OUTPUT
Enter the limit:10
Random Numbers in the given Limit:
84
87
78
16
94
36
87
93
50
22
Simple Program: Simple Program to generate 10 random numbers in C. This program will generate a sequence of random numbers in every program run.
#include <stdio.h> #include <stdlib.h> int main(void) { for(int i = 0; i<9; i++){ printf(" \n%d ", rand()); } return 0; }
OUTPUT
1804289383
846930886
1681692777
1714636915
1957747793
424238335
719885386
1649760492
596516649
Please Login to Post the answer