Hi,guys! I study about how to generate a random number recently,a lot of articles said "Linear Congruential Generator" is a frequently-used method!However,I used the mothod rand() in the stdlib.h,which is a lib function of keil,I observed it seems as if it don't use this kind of method,do it???
Keil produce 4 different toolsets for quite different architectures; I don't think there's any particular reason to beleive that they would all use the same algorithm?
Specifically for C51, see: http://www.keil.com/forum/docs/thread3859.asp
The following is the code of the Rand() in the lib of keil:
C:0x008E AC0D MOV R4,?SRAND?BYTE(0x0D) C:0x0090 AD0E MOV R5,0x0E C:0x0092 AE0F MOV R6,0x0F C:0x0094 AF10 MOV R7,0x10 C:0x0096 7810 MOV R0,#0x10 C:0x0098 EC MOV A,R4 C:0x0099 4D ORL A,R5 C:0x009A 4E ORL A,R6 C:0x009B 4F ORL A,R7 C:0x009C 7004 JNZ C:00A2 C:0x009E 7CA5 MOV R4,#0xA5 C:0x00A0 7DA5 MOV R5,#0xA5 C:0x00A2 C3 CLR C C:0x00A3 EC MOV A,R4 C:0x00A4 13 RRC A C:0x00A5 FC MOV R4,A C:0x00A6 ED MOV A,R5 C:0x00A7 13 RRC A C:0x00A8 FD MOV R5,A C:0x00A9 EE MOV A,R6 C:0x00AA 13 RRC A C:0x00AB FE MOV R6,A C:0x00AC EF MOV A,R7 C:0x00AD 13 RRC A C:0x00AE FF MOV R7,A C:0x00AF 5010 JNC C:00C1 C:0x00B1 EC MOV A,R4 C:0x00B2 64CC XRL A,#0xCC C:0x00B4 FC MOV R4,A C:0x00B5 ED MOV A,R5 C:0x00B6 644C XRL A,#0x4C C:0x00B8 FD MOV R5,A C:0x00B9 EE MOV A,R6 C:0x00BA 644E XRL A,#0x4E C:0x00BC FE MOV R6,A C:0x00BD EF MOV A,R7 C:0x00BE 64CE XRL A,#0xCE C:0x00C0 FF MOV R7,A C:0x00C1 D8DF DJNZ R0,C:00A2 C:0x00C3 8C0D MOV ?SRAND?BYTE(0x0D),R4 C:0x00C5 8D0E MOV 0x0E,R5 C:0x00C7 8E0F MOV 0x0F,R6 C:0x00C9 8F10 MOV 0x10,R7 C:0x00CB EE MOV A,R6 C:0x00CC 547F ANL A,#0x7F C:0x00CE FE MOV R6,A C:0x00CF 22 RET
but i can't read it clearly! Is there anyone can explain what the algorthim it uses? Or,is there source code of it?!Thanks a lot!!!!!!!
"but i can't read it clearly!"
Seriously? Even a quick glance shows it's an LSFR implementation.
If you don't get that right off the bat, play computer and write down the register values and all the effects of instructions interacting on said registers. Imagine objects of 16 or 32 bits in size being acted upon. Model that in C and it will boil down to a handful of C statements.
Even a quick glance shows it's an LSFR implementation.
It's LFSR, to be exact. Don't let typos confuse the original poster even more. Here is the Wikipedia link: en.wikipedia.org/.../LFSR
There is an artical about keil generates the random with LSFR: http://www.keil.com/forum/docs/thread3202.asp what is : Masks for 3-bit galios LFSR maximum run length generator Masks for 8-bit galios LFSR maximum run length generator Masks for 10-bit galios LFSR maximum run length generator ... Masks for 32-bit galios LFSR maximum run length generator why masks the register?!
"There is an artical about keil generates the random with LSFR"
Indeed - and its first paragraph gives a link to an article explaining the technical details!
If you really want to get into this, then you are going to have to get down to some serious study - it is beyond the scope of this forum!
I understand the LSFR roughly,but seems that keil dosen't use it?!There is no some kind of masks for registers in LSFR?!