This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to generate random number?

Does anybody know how to generate random number using 8051?

Parents
  • From the keil help books/files:-

    #include <stdlib.h>
    int rand (void);
    Description:
    The rand function generates a pseudo-random number between 0 and 32767.

    Return Value:
    The rand function returns a pseudo-random number.

    Is this what you want? if not it should be fairly easy for you to scale the returned value to whatever range you need. Alternativly for eg. go here http://www.agner.org/random/ for further info/theory/code on coding a pseudo random number generator or http://www.programmersheaven.com/zone5/cat27/30104.htm seems to have code for an asm version which you may find useful.

    Mark :-)

Reply
  • From the keil help books/files:-

    #include <stdlib.h>
    int rand (void);
    Description:
    The rand function generates a pseudo-random number between 0 and 32767.

    Return Value:
    The rand function returns a pseudo-random number.

    Is this what you want? if not it should be fairly easy for you to scale the returned value to whatever range you need. Alternativly for eg. go here http://www.agner.org/random/ for further info/theory/code on coding a pseudo random number generator or http://www.programmersheaven.com/zone5/cat27/30104.htm seems to have code for an asm version which you may find useful.

    Mark :-)

Children