Page 1 of 1

some (useful) remarks about particleemitter

Posted: 19 Aug 2008, 02:13
by ManaTux
in fact about randomness in general...
The use of rand() should be avoided. Not because of poor randomness, of course you don't need better quality, but because of performance. The overhead caused by repeated function calls can be significant for particles generation.

I would recommend to replace rand with a more efficient custom function.
you might use the glibc rand definition (according to http://en.wikipedia.org/wiki/Linear_con ... _generator)

Code: Select all

unsigned int state=0x19082008;  //might be seeded somewhere

inline int myrand(){
  state = (state*1103515245)+12345;
  return state & RAND_MAX;
}
(putting this inside a class could be better)

this gives a 10x faster rand

This is really easy to do (mainly change only minmax.h) and can bring better performance for large particles systems.
It is also really clear and easy to use...
If you find some reason not to use this... I would be glad to hear them!