C program to generate random number

devquora
devquora

Posted On: Dec 23, 2020

C program to generate random number

 

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 palindrome and explain it with output.

Table of contents:

  1. What is a Number?
  2. What is random number?
  3. Demonstration to generate random number
  4. Logic to generate random number
  5. C program to generate random number
  6. Explanation of the C program to generate random number with output.
  7. Conclusion

What is a Number?

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, Number is a combination of digits, some symbols and decimal points. For instance, 127.23 is a rational number.

What is 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 random number

random numbers

Logic to generate 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 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:

c program to generate random number

 

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

    Related Questions

    Please Login or Register to leave a response.

    Related Articles

    C Program Examples

    C Program to convert Decimal to Binary Number

    A Decimal Number is constructed with any digit from 0 to 9. For instance, 24 is a Decimal Number constructed from the digits 2 and 4. A Binary Number is constructed with digits 0 and 1. For instance, ..

    C Program Examples

    C program to reverse a string

    This program reversed the entered string that means opposite of the previous string sequence...

    C Program Examples

    C program to reverse an Integer number

    Are you want a demonstration of The C Program that reverses an Integer number? This Program reversing the sequence of digits in an Integer. After the successful compilation of the program, a message..