[SOLVED] Generating random code using rand() function in mikroc

Status
Not open for further replies.

Mathi_theboss

Newbie level 5
Joined
Mar 28, 2013
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,351
How to generate 4 digit random code using rand() function in mikroc? can anybody help me...
 


Code C - [expand]
1
2
3
4
5
6
int result;
void main()
{
 result = rand();
 result = result/10;
}



- - - Updated - - -

rand()
Function returns a sequence of pseudo-random numbers between 0 and 32767.
So it is 5 digit sequence, dividing by 10 will work, hope so


Code C - [expand]
1
2
3
4
5
6
int result;
void main()
{
 result = rand();
 result = result/10;
}

 

Thank you guys... i got solution for this.

random_no=rand()%8999 + 1000;

The above code will generate random no of exactly 4 digits...
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…