How to generate random numbers in c





How to generate random numbers in c
C code to generate random numbers 


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(){
    int num;

    //initialize the random number generator
    randomize();

    //Generating the random number
    num = random(99999);

    //Printing the random number
    printf("%d",num);
    getch();
    return 0;
}

Note: random function random(val) generates any number between 1 to num -1 . randomize() function is used only to initialize the random number generator. It internally call the used the header file time.h




Post a Comment