This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430-3P-AWGH-AMB8423-DEVBD: I want to generate a random no. with the help of ADC.

Part Number: MSP430-3P-AWGH-AMB8423-DEVBD


Tool/software: TI C/C++ Compiler

I want to generate a random No. with maximum randomness with the help of ADC.

Please help.

  • Here is a similar thread: e2e.ti.com/.../215312

    Other available resources on the subject:

    www.ti.com/.../slaa338.pdf
    processors.wiki.ti.com/.../MSP430_FAQ

    Regards,
    Ryan
  • Using the ADC to generate a seed is a good start. You could leave the pin floating, and then take the LSB from several measurements to construct your initial value - ie if your seed is 8-bits take the LSB from 8 ADC readings. To maximise randomness, try to use an ADC pin that is close to other interfaces that will be active at the same time, close to devices that change in temperature etc... anything to increase entropy. But then you should feed that initial value into a PRG to generate the rest of your random numbers. You could probably implement a simple linear-feedback shift register (LFSR).
  • Chris Karaplis said:
    You could leave the pin floating, and then take the LSB from several measurements to construct your initial value

    Floating pin is bad idea. -  Pin can "receive" periodic signal which is far from random. Imagine if pin receives AC mains EMI and ADC sampling freq is way higher than AC freq, like 500 SPS - then you will get strings of 1's and 0's like 0000111111000000111111. No randomness at all.

  • This is true. Its far from ideal and there are definite risks with doing that. You would have to experiment to see what level of randomness can be achieved. I am sure there is a better way to do it other than floating, but I am not sure what that would be. Since Jagrati is using a dev board I am assuming he can only implement so much in HW and may have to do the best he can with what he has. I wonder if there is any way you could connect the ADC pin to the wireless receiver. That might be more likely to be random.
  • Creating good hardware entropy source for random number generator is not a trivial task, some are even patented. One of well-known noise source is zener diode - if powered from noiseless voltage source. Instead of using floating pin, I would suggest to sample channel 0x0b (internal VCC divider) using VCC as reference. Obviously as Chris already suggested, only LSB shall be used for entropy, thou quality of such enropy generator remains to be seen.. When enough entropy bits are collected, it is wise idea to scramble them with AES-CTR or similar crypto/hash algorithm

  • You could leave the pin floating

    The sample-and-hold circuit of the ADC is likely to discharge any random charge.

    An easy way to get a guaranteed amount of entropy from an ADC input is to connect a resistor and measure the Johnson noise (see, e.g., Turbid).

  • Clemens Ladisch said:
    The sample-and-hold circuit of the ADC is likely to discharge any random charge.

    Did you ever continuously sampled floating pin of msp430 charge redistribution ADC? :) You shall try. Thing is that whole ADC have around 27pF internal capacitance, LSB capacitor is fraction of that. Not that much charge is needed to flip it.

**Attention** This is a public forum