Skip to main content
gamedev.net
🔒 Locked

generate random float values?

Started by binium 2 replies 250+ views
Original Post
binium
binium
How can I generate a random float value ranging (-m, m), m is a any float value? Thanks a lot!
niyaw
niyaw
use rand().
Neosmyle
Neosmyle
#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]
binium
binium
Thanks, buddies!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.