Advertisement

looking for a rand( ) function for floating point

Started by September 05, 2002 03:48 PM
2 comments, last by tylerbingham 22 years, 5 months ago
I was wondering if anyone had a good macro or inline function for randomizing a floating point number. Like for numbers between 0.0f and 1.0f or 0.0f and -1.0f. [edited by - tylerbingham on September 5, 2002 4:51:03 PM]
You could use: (float) rand() / (float) RAND_MAX
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Advertisement
I use this for my particle engine :

float speed[]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};//and so on..
//and also use this :
srand(GetTickCount());
or
#include <time.h>
srand((unsigned)time(NULL));
Particle.life=speed[rand()%9];//since they are 9 numbers...

Relative Games - My apps

Plenty of random number generators and distribution functions there.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement