Random Number C Program

C Program To Find Random Number in a Range

Learn How To Find and Print Random Number in C Programming Language. This C Program makes use of the rand() method to print the random numbers. However, the srand() method can also be used to find the random numbers.

What is rand() method?

The C rand() function generates a pseudo random number between 0 and a number defined in a range. It has its definition in the standard library header file – stdlib.h. Using a modulus operator with the rand() method gives a range to the random integer generation.

num = rand() % 10 indicates the compiler than the random integer should be within 0 and 10, where 10 acts as the RAND_MAX value. This is how you can generate a random number in C programming.

You can even add your own algorithms to improve the random number generation. It may include something like the following:

C Program To Find Random Number using Rand() Function

C Program To Generate Random Numbers Between 1 and 10


 C Program To Print Random Number From 1 To 10

If you have any doubts or compilation errors in this C Program To Generate Random Integers in a given Range, let us know about it in the comment section below.

Recommended Programs
C Program To Convert Hexadecimal To Decimal Number
C Program To Print Pascal Triangle
C Program To Sort Array in Descending Order
C Program To Find Magic Number
C Program To Check Strong Numbers
C Program To Check Strong Numbers
C Program To Find LCM of N Numbers
C Program To Generate Series for Arithmetic Progression
C Program To Find Smallest Digit of a Number
C Program For Recursive Descent Parsing

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

5 thoughts on “Random Number C Program

  • November 20, 2016 at 2:00 pm

    The rand() function is not secure enough in terms of cryptography. You must compile your own algorithm if you want to implement it in the real world systems.

  • November 21, 2016 at 4:52 pm

    Amazing code for random number generator in C programming.

  • November 21, 2016 at 8:56 pm

    Which are the other methods for generating random numbers in C programming?

  • November 21, 2016 at 8:58 pm

    Although there are multiple methods for generating random integers in C programming language, it does not possess good algorithms as such. Here are some of the enlisted:

  • 1. randomize()
  • 2. rand()
  • 3. srand()
  • Reply
  • November 22, 2016 at 3:59 am

    Abundant knowledge is what I get here at CodingAlpha. The explanation for this random number is just too good.


Join The Discussion