Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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,060
Helped
2,149
Reputation
4,304
Reaction score
2,088
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
check this
**broken link removed**

---------- Post added at 08:21 ---------- Previous post was at 08:18 ----------

this has everything you want.. just register yourself in this site to access everything
**broken link removed**
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,418
Helped
1,175
Reputation
2,369
Reaction score
1,169
Trophy points
1,403
Location
Brazil
Activity points
54,764
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top