Random Number C Program

By | November 20, 2016

Let us 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

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

Output

 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

5 thoughts on “Random Number C Program

  1. Mayank Rathor

    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.

    Reply
  2. Sanmesh Sawant

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

    Reply
  3. Nayan Patil

    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:

  4. 1. randomize()
  5. 2. rand()
  6. 3. srand()
  7. Reply
  8. Akshay Bramhe

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

    Reply

Let's Discuss