Random Number Generation in LPC 1343 using ADC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Random Number Generation in LPC 1343 using ADC

761 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by veereshdandur on Mon May 21 15:45:39 MST 2012
Hi, I need a help urgently. I am trying to generate the random number using ADC. Below is my code.

void ran_gen(uint16_t n, uint8_t *var) {
uint16_t i=0,seed;
uint8_t lsb;

  ADCInit(ADC_CLK);

seed=0;
for(i=0;i<32;i++) {
lsb=ADCRead(1);
seed|=(lsb<<i);
}
 
srand(seed);
        for(i = 0; i < n; i++) {
//var = Chars[rand()%(62)];
var=rand();
}
var[n] ='\0'; // Just to make sure the string is terminated

}
But whenever I try to ADCread(), the seed is always set to 0 and resulting in same values every time I try generating random number. I don't understand why I am unable to read from ADCread. Help me please.:confused::confused::confused:
0 Kudos
Reply
0 Replies