hglm/libfgen

Random number generator has room for improvement.

Closed this issue · 1 comments

hglm commented

The random number generator used in libfgen, although fast and well distributed statistically, has some room for improvement. This includes avoiding integer remainder, instead using a "retry" approach when the value is above the range, avoiding the use of a look-up table, and most importantly allowing higher precision when generating random floating point values.

Optimizations similar to those mentioned above (and other improvements) have already been implemented in the random number generator module in the "sre" (SRE rendering engine) repository, written in C++, and need to be ported to libfgen's C environment.

Although not yet tested, the improved speed and higher floating point precision have the potential to significantly improve performance of applications using libfgen (such as texgenpack, or scientifically-oriented applications that use floating point values).

hglm commented

Random number generator code similar to sre-random has now been integrated into libfgen, along with a few other optimizations. A measurable speed improvement is seen in several test programs and applications (such as texgenpack).

Higher performance would be possible by allowing inlining of random value requests, which is already offered by sre-random in a C++ class. It would require some work to adapt libfgen's C main code base to be able to use sre-random or otherwise allow inlining.