📄 randomm.nc
字号:
module RandomM { provides interface Random;}implementation{ uint16_t shiftReg; uint16_t initSeed; uint16_t mask; /* Initialize the seed from the ID of the node */ async command result_t Random.init() { dbg(DBG_BOOT, "RANDOM_LFSR initialized.\n"); atomic { shiftReg = 119 * 119 * (1 + 1); initSeed = shiftReg; mask = 137 * 29 * (1 + 1); } return SUCCESS; } /* Return the next 16 bit random number */ async command uint16_t Random.rand() { bool endbit; uint16_t tmpShiftReg; atomic { tmpShiftReg = shiftReg; endbit = ((tmpShiftReg & 0x8000) != 0); tmpShiftReg <<= 1; if (endbit) tmpShiftReg ^= 0x100b; tmpShiftReg++; shiftReg = tmpShiftReg; tmpShiftReg = tmpShiftReg ^ mask; } return tmpShiftReg; } // uint16_t TOSH_rand() __attribute__((C)) {// return call Random.rand();// }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -