Random float ?

how to make a random float between -1.0f and 1.0f or something like that?

float randomNumber = (2.0 * float(rand()) / float(RAND_MAX)) - 1.0;

Or something like that.

Originally posted by McZ:
how to make a random float between -1.0f and 1.0f or something like that?

This is an old code that I have used (if you do not want to rely on rand()). It works very well:

double myrand( void )
{
static unsigned long seed = 123;
seed = (1103515245L * seed + 12345L ) & 0x7fffffffL;
return 1.0 - ((double)seed/(double)0x3fffffff);
}

Of course, you can expand it to use a configurable seed etc…

/Marcus