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

Generating a Random number for ARM7

I have to generate a random number by taking the input as a timer value...
SO can anyone suggest how to get this????

Thanks in Advance

Parents Reply Children
  • Sorry for my very limited English and technical ability, I guess this

    srand(rand());
    


    is a really bad idea, am I right?


    The srand() function uses the argument as a seed for a new sequence of pseudo-random numbers to be returned by subsequent calls to rand(). If srand() is then called with the same seed value, the sequence of pseudo-random numbers shall be repeated. If rand() is called before any calls to srand() are made, the same sequence shall be generated as when srand() is first called with a seed value of 1.

    I noticed that it is 1-Apr-2011 now. But just not so sure.

  • "...a really bad idea, am I right?"

    Yes, you are right.

    No, it is nothing to do with April 1st. I really did see that line of code!

    The line of code was being executed close to the start of main, so the seed for the pseudo-random number generator had been set by the initialisation of the library. The first random number produced was identical from one reset to another. So the value passed to srand was always the same. So subsequent calls to rand always produced the same sequence of values.