3

I need a seeded random uniform distribution generator (in range [0, 1]) that can be coded using SIMD built with -march=nocona.

Xorshift https://en.wikipedia.org/wiki/Xorshift or Hash https://github.com/skeeto/hash-prospector seems good choices for this task.

The problem seems to map uint32/64 values into floats, which are not well suited to translate in single (float) precision (due to conversion and limited space between tiny floats).

Which mapping would you suggest? It must be 32x4 vectorized, uniform spaced in range 0-1, seeded and quite light on CPU (audio application processing at audio rate; I'll use it to make white noise audio signal).

markzzz
  • 47,390
  • 120
  • 299
  • 507
  • 2
    For white noise you want a Gaussian distribution, not uniform. – Paul R Apr 24 '21 at 20:17
  • @PaulR not really – markzzz Apr 24 '21 at 21:51
  • What is the minimum required period for the generator? What is the maximum allowable state? "_XorShift or Hash seems good..._" - 32 bits -> `float` requires one mask (or shift operation) + one multiplication by a constant. "_What would you suggest?_" - Does it need to be equidistributed in 4 dimensions, as in "each sequence of 4 32 bit words will occur equally often"? If so, why? Is the range `[0, 1)` or `[0, 1]`? Define "fast". 10^6 generated numbers/second? 10^50? (asking for a friend) – Ted Lyngmo Apr 24 '21 at 21:57
  • @TedLyngmo: The first paragraph mentions a `[0, 1]` range. Agreed that mapping uniform bit-patterns from an integer PRNG to IEEE floats is the obvious way to proceed, the trick is choosing a mapping. That's what the OP [was planning before I encouraged him to ask a new question](https://stackoverflow.com/questions/67225382/how-would-you-port-this-unsigned-int-scalar-code-to-signed-int-vector#comment118834349_67225382) because comments on another question weren't the right place to figure out all the gotchas of floats and RNGs, and apparently it morphed into this rejection of the whole idea?! – Peter Cordes Apr 25 '21 at 00:37
  • @PeterCordes why rejection? The topic is the same, isn't? – markzzz Apr 25 '21 at 07:06
  • This question seems to be saying you don't want to use Xorshift at all. Or at least that's one way to interpret it. I suggested asking how to map a random integer bit-pattern to uniform random floats (which is what you were trying to do before). It's fine to broaden the question to include other possible approaches, but your phrasing seemed weird, like you weren't even considering that approach anymore. Perhaps that's not how you meant it. But you didn't mention any of your ideas like multiplying by 2^-32 (which is the same as dividing by `(float)0xFFFFFFFF` after rounding.) – Peter Cordes Apr 25 '21 at 07:09
  • @PeterCordes oh no! Sorry for the misundertanding (language fault). Using those algo is ok for generating quality uniform distribution. The problem stay in the mapping to the float domain. I edit the question to make it even more clear, sorry. – markzzz Apr 25 '21 at 07:12
  • @PeterCordes edited. Is it better now? – markzzz Apr 25 '21 at 07:19
  • Yeah, somewhat, although "not well suited" is still a weird way to describe the challenges. Also still a duplicate; I thought I'd searched on SIMD FP RNG before, but maybe one of the keywords I used wasn't one that appeared in the existing Q&As. (Which do exist after all, so this is clearly a duplicate, unless you have specific requirements those don't meet. If so, mention them in your question and explain why that question / its answers are different from what you need, so answerers can see the diff, and future readers with variations on the problem can find stuff.) – Peter Cordes Apr 25 '21 at 07:25
  • 1
    @PeterCordes We must have missed the range within parentheses. My friend just wanted some clarifications. It wasn't meant as rejecting the idea. – Ted Lyngmo Apr 25 '21 at 08:02

0 Answers0