Generate 64-bit values ​​with 32-bit Mersenne Twister

According to this Boost documentation page , the 64-bit version of the Mersenne Twister is much slower than its 32-bit counterpart (which makes sense). As far as I understand, many functions introduced in C ++ 11, including random number generation, are mostly Boost in the standard library. This makes me think that the 32-bit MT performance in standard C ++ is also better.

I write a raytracer (for fun, mostly), and speed is one of my main concerns. In fact, all numerical values ​​are represented as floating values ​​with double precision. My question is, since 32-bit MT is significantly faster, can I use it to generate doubles? What disadvantages (precision loss, performance, etc.) can be expected?

+6
source share
1 answer

For this, I add one assumption that you did not mention: I assume that you make one random draw for a double. Obviously, you can get twice an accident by doing two draws.

The first question really "makes 32-bit pseudo-randomness random enough for my ray indicator." I think yes. Most raytracers only shoot from a few million rays, so you will not notice that there are only 4 billion bits of pseudo-randomness.

Second question: “Can I spread pseudo-randomness in the field of double values ​​that I care about.” Again, I think so. If you shoot rays in a 90 degree field, and there are 4 billion possible results from one pseudo-random draw. For perspective, a sniper scanning a powerful field of view sees millions of times less angular accuracy than the average difference between these pseudorandom vectors.

All that is said is the profile of your code. I would give a 99.9998% chance that your trace code itself will take much longer than the pseudo-random generation, unless your scenes consist of separate non-reflective spheres.

+2
source

Source: https://habr.com/ru/post/953840/


All Articles