tinyos2.x/tos/interfaces/中提供了组件Random.nc,其提供了两个命令:async command uint32_t rand32()、async command uint16_t rand16();调用的时候直接int16/32_t num=call Random.rand16/32()即可。
给出简单的Blink例子
1.更改BlinkC.nc
#include <Timer.h>
module BlinkC{
uses interface Timer<TMilli> as Timer0;
// uses interface Timer<TMilli> as Timer1;
// uses interface Timer<TMilli> as Timer2;
uses interface Leds;
uses interface Boot;