2011-07-23 21:47:42 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include "random.h"
|
|
|
|
#include "xxtea.h"
|
|
|
|
|
|
|
|
#define STATE_SIZE 8
|
|
|
|
uint32_t state[STATE_SIZE];
|
|
|
|
uint32_t const I[4] = {12,13,14,15};
|
|
|
|
|
|
|
|
void randomInit(void)
|
|
|
|
{
|
|
|
|
uint32_t i,j,x;
|
|
|
|
for(j=0; j<STATE_SIZE; j++){
|
|
|
|
x = 0;
|
|
|
|
for(i=0; i<10240; i++){
|
|
|
|
x ^= (adcRead(1)&1)<<(i%32);
|
|
|
|
}
|
|
|
|
state[j] = x;
|
|
|
|
}
|
|
|
|
xxtea_encode_words(state, STATE_SIZE, I);
|
|
|
|
}
|
|
|
|
|
2011-07-24 13:58:47 +00:00
|
|
|
uint32_t getRandom(void)
|
2011-07-23 21:47:42 +00:00
|
|
|
{
|
|
|
|
xxtea_encode_words(state, STATE_SIZE, I);
|
|
|
|
return state[0];
|
|
|
|
}
|