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

The rand() function.

The rand() function in the stdlib.h is suppost to generate random numbers.
However in C programming the random number is generated from a variable eg time, date,..

Then in Keil, and the controller, how does this rand() function work..

Cause i tried using it, it worked ok..
The problem is everytime the controller is reseted, it generates the same set of random numbers. And if u randomize again, it will just become a patern instead of a random value..

Example:

after reset:

3,5,8,1,4,...etc etc..

after the reset button again...

3,5,8,1,4,...etc etc..


Does this mean there is no other way to generate random numbers?

Parents
  • Means it does not really generate a random number rather than a set of psedovalues.

    To implement a random value in a system every time it is boot up, we must then use a memory element to store and increament a value each time a system is started for the srand() value. This is to ensure each different set of psedorandom value is generated every time the system is booted up.

    Maybe at first i didn't understand what psedo number means..

    Thanks.

Reply
  • Means it does not really generate a random number rather than a set of psedovalues.

    To implement a random value in a system every time it is boot up, we must then use a memory element to store and increament a value each time a system is started for the srand() value. This is to ensure each different set of psedorandom value is generated every time the system is booted up.

    Maybe at first i didn't understand what psedo number means..

    Thanks.

Children