I would assume that rand16() returns a 16 bit random number
so you will have to do some calculating to range it to 0->1.
But I recommend avoiding floating point on the controller side
whenever possible because there is no hardware support for it.

I don't know why you get the same number on each call as I would
expect the float cast to just give you the int16 values themselves.
Maybe try making your "random" variable an int and see what...

Also look at the Random interface, there should be some kind of seed()
call which would allow starting the pseudo sequence from a different
point on each of your motes. The easiest would be to use the moteID
as the seed on each device.

MS

Hanen Rekik wrote:
> Hi,
> I use TOS 2.1.1 and I am trying to generate rando*m* numbers between 0 and 1, 
> also I want to have  different random numbers at the different motes.
> 
> I am using Random interface, RandomC component and float random = call 
> Random.rand16(); but I didn't get a value between 0 and 1, and always I get 
> the same random number.
> How should I write the code.
> Please help.
>  
> //
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help@millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to