float random_value(int min, int max)
{
float temp = rand() / (float) RAND_MAX;
return min + temp *(max - min);
}
我有这个功能,但它在 cooja 中不起作用,因为它总是一遍又一遍地输出相同的数字,而且我没有 time.h 库来制作srand()
. 那么,我应该如何在 cooja 中打印不同的随机浮点值?我应该编写float random_value (float min, float max)
可用于实现虚拟温度传感器的 ac 函数,该传感器可配置为生成最小值和最大值之间的值。