[Tinyos-help] how to get a random float number

Tarun Bansal bansal.tarun at gmail.com
Tue Feb 13 21:56:27 PST 2007


Use rand_no = random();
This would return an integral random number between 0 to RAND_MAX. So
you can divide the result by RAND_MAX to get a floating number between
0 and 1 (It won't be a real floating point random number as the set of
floating numbers that you get here is limited)

To generate better floating point numbers, I generate two random
numbers. Scale first of them to 0-1 and second to 0- (1/RAND_MAX) .
Then use second to add small amount of noise to the first number by
adding them up.


Tarun
http://bansal.tarun.googlepages.com/


On 2/14/07, Shen Ke <shenke at cityu.edu.hk> wrote:
>
>
> How can I get a random floating number between 0~1?
>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help at Millennium.Berkeley.EDU
> https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>


More information about the Tinyos-help mailing list