per-pixel random problems?

Matthew Woehlke mw_triad at users.sourceforge.net
Thu Dec 11 22:58:28 CET 2008


Cyrille Berger wrote:
> it's not erand... We need a non recursive function to be able to compute it's 
> value at every pixel independentely of other values. Being integer based 
> (unlike the current one) would be a huge bonus, since I discovered since that 
> time that floating point units in CPU are buggy and give very different 
> results from one arch to an other...

Honestly I'm not clear why erand48 doesn't work (it doesn't, I've been 
playing with it in a stand-alone program). You'd think with suitably 
large and semi-prime numbers, you could get a distribution where A*x % b 
results in a halfway decent f(x) for reasonable B. Alas, seems not.

Well, what I did for my plasma stand-alone is run (x%5 + y%37) 
iterations. It seems to give an acceptable result, but it's relatively 
expensive :-).

> On Thursday 11 December 2008, Matthew Woehlke wrote:
>> The png is substantial (500+kb), so I dumped it at
>> http://img124.imageshack.us/img124/9986/noisetesthq8.png. (Um. And
>> ImageShack no longer works without scripting or View Source; guess I
>> won't be using them any more.)
> Here is what I get: http://cyrille.diwi.org/tmp/noise.png

It's not as bad, but I would say there are artifacts there also. Hmm... 
I wonder how much difference using long double makes, it may be that 
you're getting 80-bit calculations and I am not?

Anyway, this simple change... well, looks at least as good as yours, 
maybe a *tiny* bit better. I'm wondering if some of it is just in my 
head ;-). Regardless, this makes things on /my/ end a lot better:

Index: image/kis_random_generator.cc
===================================================================
--- image/kis_random_generator.cc       (revision 895863)
+++ image/kis_random_generator.cc       (working copy)
@@ -46,8 +46,8 @@
      // To plot it in Octave :
      // t = 1:1:100000;
      //plot (t, sort(0.5*(cos( cos(cos(t.*t.*t.*t))) + 1)));
-    // This function has a near-gaussian distribtution
-    int n = x + (y + 1) * d->seed;
+    // This function has a near-gaussian distribution
+    quint64 n = (quint64(x) * 1103515249) + (quint64(y) * 91573) + d->seed;
      return 0.5*(cos(pow(n, 4)) + 1);
  }

(note also the spelling correction ;-) )

I may keep fiddling with a pure-integer random function.

-- 
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
-- 
|-\ /-\ \ | -+-   |-\  +  \ | -+- /-\
| | | | |\|  |    |-/ /-\ |\|  |  |
|-/ \-/ | \  |    |   | | | \ -+- \-/



More information about the kimageshop mailing list