#include "system/task_rand.h" #include "system/hardware_task.h" #include "system/data_channel.h" #include "system/float_word.h" #include int task_rand_run( void * data ) { rand_config * task = ( rand_config * ) data; uint32_t data_channel_base = task->base.sink; float seed = task->seed; //1.3 float abs_min = task->abs_min; //0.125 float abs_max = task->abs_max; //9.0 float_word random_number; random_number.value = seed; uint32_t mask_bit_0 = 0x1; uint32_t mask_bit_1 = 0x2; uint32_t mask_bit_21 = 0x200000; uint32_t mask_bit_31 = 0x80000000; uint32_t exponent = 0; uint32_t shifted_exponent = 0; uint32_t shifted = 0; uint32_t shifted_modifiziert = 0; data_channel_clear( data_channel_base ); for(uint32_t i = 0; i < DATA_CHANNEL_DEPTH; ++i) { //Bits extrahieren: uint32_t bit_0 = (random_number.word & mask_bit_0) >> 0; uint32_t bit_1 = (random_number.word & mask_bit_1) >> 1; uint32_t bit_21 = (random_number.word & mask_bit_21) >> 21; uint32_t bit_31 = (random_number.word & mask_bit_31) >> 31; //XOR: uint32_t xor_result = bit_0 ^ bit_1 ^ bit_21 ^ bit_31; //Shifted: shifted = random_number.word >> 1; //shifted &= ~(0x80000000); shifted |= (xor_result << 31); printf("%08x %08x %d \n", random_number.word, shifted, xor_result); //Skalierung: #if 1 exponent = (shifted >> 23) & 0xFF; if(exponent & (1 << 7)){ exponent &= (0b10000001); }else{ exponent |= (0b01111100); } shifted_modifiziert = shifted; shifted_exponent = exponent << 23; shifted_modifiziert &= 0x807FFFFF; shifted_modifiziert |= shifted_exponent; #endif random_number.word = shifted_modifiziert; data_channel_write( data_channel_base, random_number.word ); random_number.word = shifted; } return 0; }