C program for generate random numbers

To generate random number in C program we using random() function of stdlib.h.

                              int random(int n);
which generate the random number in the range of o to n-1.

For example:
                              y = random(100);

which generate a random number in between the 0 to 99 and store them in y.

This random function is generally generate same number each and every time while you run the program. So every one can know that what is next number so for that we need to use randomize() function.

 randomize() function generate the number as per the system clock. So its different every time. For this you just need to mention randomize(); before using random(); function. For more understanding see the below example of c program.

Source Code to Generate Random Numbers.

#include<stdlib.h>// for using random() function

void main()
    int A[10];
    int i,n,j;

    printf("5 random numbers (0-100) are as follows.\n");
    randomize();// to generate different random number
                       //every time.

            A[i]=random(100);// it generate random number
                                 //in the range of 0-99.



c program to generete random number


Post a Comment