Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

random number generation with at89c51 using C

Status
Not open for further replies.

nyxon

Newbie level 2
Joined
May 25, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,295
i m tryin to create a dice for which random no. generation is necessary.
i had used rand() function under stdlib.h but it keeps on givin the same no.
what are other method of generation random no. using C language

my code was like this

int r;
r=rand()%7;

this should generate random no. between 0 to 6 but instead it generated only 2 every time it is executed.

plz help!!
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,097

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,222
Helped
1,148
Reputation
2,315
Reaction score
1,124
Trophy points
1,403
Location
Brazil
Activity points
53,690
nyxon

You must provide the seed before call that function.
That´s because RAND performs a pseudo-randomizing algorithm.
Generally we use an assyncron event to trigger an internal uC counter and feed the function.

+++
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top