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 <[EMAIL PROTECTED]> wrote:


How can I get a random floating number between 0~1?

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to