crashtest-r0ket/firmware/basic/random.c

28 lines
522 B
C
Raw Normal View History

#include <stdint.h>
#include "random.h"
#include "xxtea.h"
2011-08-01 03:22:24 +00:00
#include "core/adc/adc.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);
}
uint32_t getRandom(void)
{
xxtea_encode_words(state, STATE_SIZE, I);
return state[0];
}