Overview:
In this article, I want to explain What is number, random number? Moreover, I will demonstrate how to generate random number. Then, explain Logic to generate random numbers and write a C program to generate random numbers. After all, I will explain the C program to generate random numbers with output.
After all, I will write the logic of a C to check if the number is a palindrome and explain it with output.
Table of contents:
- What is a Number?
- What is random number?
- Demonstration to generate random number
- Logic to generate random number
- C program to generate random number
- Explanation of the C program to generate random number with output.
- Conclusion
What is a Number?
A number is an object that uses digits to perform mathematical tasks. Calculus, which is a branch of mathematics, includes many numbers such as integers, whole numbers, real numbers, and imaginary numbers. Here, I will discuss numbers to perform arithmetic addition operations. Moreover, a Number is a combination of digits, some symbols, and decimal points. For instance, 127.23 is a rational number.
What is a random number?
Random numbers are numbers that occur in a sequence such that two conditions are met: (1) the values are uniformly distributed over a defined interval or set, and (2) it is impossible to predict future values based on past or present ones. Random numbers are important in statistical analysis and probability theory.
Demonstration to generate a random number
Logic to generate a random number
- Step 1: We use a modulus operator in our program. If you evaluate a % b where a and b are integers then result will always be less than b for any set of values of a and b.
- Step 3: For example, For a = 1243 and b = 100 then, a % b = 1243 % 100 = 43
- Step 5: For a = 99 and b = 100 then, a % b = 99 % 100 = 99
- Step 7: For a = 1000 and b = 100 then, a % b = 1000 % 100 = 0
C program to generate a random number
#include #include int main() { int c, n; printf("Ten random numbers in range [1-100] are as follows: "); for (c = 1; c <= 10; c++) { n = rand() % 100 + 1; printf("%d, ", n); } return 0; }
The output of the Program with code:
Conclusion:
Random numbers are numbers that occur in a sequence such that two conditions are met: (1) the values are uniformly distributed over a defined interval or set, and (2) it is impossible to predict future values based on past or present ones. Random numbers are important in statistical analysis and probability theory. After the successful compilation of the program, this program displays the following output: Ten random numbers in range [1-100] are as follows: 42, 68, 35, 1, 70, 25, 79, 59, 63, 65