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?
How does it work? You may find this link informative: http://www.programmersheaven.com/zone5/cat27/32219.htm
a true story about the importance of "pseudo". The J1708 standard specify that after a collision a reandom delay is to be inserted before the nest attempt. Two devices, both using the Keil rand(); Keil, PLEASE rename it pseudo_rand(); collided, since they both added the same delay every time the collision that started some time during a "let it run the weekend, we'll see monday" was still occuring. Erik
"Keil, PLEASE rename it pseudo_rand();" Unfortunately, the name "rand()" is defined by the ANSI/ISO standard.
It's generally a good idea to re-seed your PRNG every so many collisions, just to avoid the sort of situation Erik describes. Initial seeds usually involve the MAC address, serial number, and other such information unique per device. Packet arrival times are a common source of accumulated entropy for later seeds for networked devices. User input (keystroke times) can be useful if you have a user that inputs anything. There are schemes for fairly simple hardware devices for generating random bits, involving amplified resistor noise or tunneling in diodes. You don't really need a nuclear research lab. A Web search can lead you to designs for such things.