randomm.nc

来自「tinyos密钥管理组件 用在tinyos仿真里的」· NC 代码 · 共 45 行

NC
45
字号
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 + =
减小字号Ctrl + -
显示快捷键?