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
But you showed no indication whatsoever that you'd dony any thinking or research of your own - so what were people supposed to think?
"I asked the help how to start with"
No, you actually asked how to "get this".
But you already have your start - you said, "by taking the input as a timer value"
What thought have you given to that?
How would the timer help?
Does the standard 'C' rand function give a truly random number?
Have you searched this forum for "random" ?
Best is if srand() can be called after the program have been able to pick up some non-constant information that is different each boot.
Not so good is to use the time from the RTC (which, in case the RTC is battery-operated, would differ between each boot) since it is predictable. But since rand() itself can't produce cryptographic-strength random values, RTC data might be good enough.
Better is if there is something that will vary each boot and also can't be predicted. The problem with timers is that they run with a fixed frequency, so they are predictable. To get good use of a timer, it must run with a very high frequency and the time when it is sampled must be unpredictable. A program that always runs the same instructions between the initialization of the timer and the read-out of a timer value, will get the same values - or possibly a very small number of possible values because the CPU core may perform an asynchronous read of the timer.
An ADC might produce a _small_ amount of noise on the read data, that could, after enough reads produce enough random bits. Any interaction with a human being would produce random bits from the varying delays the human introduces between every interaction.
A "good" random source would have been the capturing of thermal noise, which would not only have given a good source of data to use for an initial call to srand(), but would allow the srand()/rand() functions to be completely ignored completely. After all, rand() just creates a limited-length series of pseudo-random numbers, where srand() controlls the start position of this series.
No reply? I'll take that as a "no", then?
www.keil.com/.../search.asp
www.google.com/search
> But you already have your start - you said, "by taking the input as a timer value" > > What thought have you given to that? > > How would the timer help?
I think you might have misunderstood the OP. He doesn't want to use the timer to generate the random number, but rather the other way 'round. I believe that the random number is supposed to serve as start value for a timer. So it should rather read: "by taking the output as a timer value".
@Per Nobody said anything about cryptographic strength. We don't know what exactly the PRN is going to be used for. There are many useful applications even for perfectly predictable PRNs.
Kindly, Marcus http://www.doulos.com/arm/
The initial post was: "I have to generate a random number by taking the input as a timer value..."
With your change, that becomes:
"I have to generate a random number by taking the output as a timer value..."
which doesn't make sense.
Only the OP can clarify this.
Well, the OP seems to have lost interest, but here's an interesting idea on how to get a truly random seed for your pseudo-random number generator (PRNG):
www.eetimes.com/.../True-random-number-generator-IP-for-ASICs-and-FPGAs
(it is applicable to microcontrollers - not just ASICs and FPGAs)
Interesting. I know that some encryption system use random noise that emanates from the atmosphere - but this, I never head of.
The Big Idea here is that it requires no additional or special hardware - it just uses what's already there as standard (the SRAM).