I wanted to know what is the best function which i can use in my code to generate a random integer between 1 and 10,000.

I m working on a channel coding algorithm and want to put a command which can generate any random number between 1 and 10,000.

The way I hav tried is : it is in BOLD.

#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<iostream.h> #include<fstream.h> int main() { FILE *f1, *f2; float eprob; int r,num=0; float x; float r_num; char a,b='0', c ='1'; f1= fopen("rcpcoutput.txt","r"); f2=fopen( "erroutput.txt","w"); printf("\n Enter the error probability"); scanf("%f",&eprob); printf("\n Error probability is %1f",eprob); while (!feof(f1)) { fscanf(f1,"%c",&a); printf("\n read is %c",a); [b] r=(10000);[/b] printf("random is %d",r); x=(float)r; r_num=x/10000; if (r_num>eprob) { if (a==b) a=c; else a=b; num++; } fprintf (f2,"%c",a); printf("random is %f probabilty is %f written is %c",r_num,eprob,a); } printf("\n\n Number of bit errors is %d",num); fclose(f1); fclose(f2); getch(); }

Please help me in solve it. The results jus reads my input bits as such. how can I get any random number ?

can some one help me learn the basics of generating a random number in C code?