generate random float values?

Started by
2 comments, last by binium 21 years, 4 months ago
How can I generate a random float value ranging (-m, m), m is a any float value? Thanks a lot!
Advertisement
use rand().
#define RANDOM_FLOAT(min, max) (((float)rand() / (float)RAND_MAX) * ((max) - (min)) + (min))

will work for any 2 floats. IE

RANDOM_FLOAT(-m, m)

EDIT- Added more parentheses

[edited by - Neosmyle on November 30, 2002 12:10:45 AM]
Thanks, buddies!

This topic is closed to new replies.

Advertisement