noise generators (forked from: Krita user community?)
mw_triad at users.sourceforge.net
Mon Feb 25 02:10:19 CET 2008
Cyrille Berger wrote:
> On Sunday 24 February 2008, Matthew Woehlke wrote:
>> (Ok, erand48 will have to go, but that's completely
>> self-contained as I've assumed from the outset that my current
>> procedural PRN formula would be only temporary... not least because it
>> turns out rand48 isn't very *good*.)
> The slight annoyance with rand48/erand48 is that those functions are not
> thread safe, and as it is recursive noise generator, it doesn't work well if
> we ask for an update of a rectangle of the generated images which is
> different from the original rect.
Eh? I'm using the flavor that claims to be re-entrant (i.e. the one that
takes the seed as an in/out). I actually do all my PRN-getting via a
myRandom() function that takes the X,Y coordinates and random seed, so
replacing mine with Krita's should be easy. (Or maybe Krita's would
benefit from my approach?)
> For this we have a random number generator
> in Krita, that takes as argument the current coordinate of the pixel. (The
> formula is probably not very *good*, but I don't know any random number
> generator formula that is very *good*).
I trust it also takes the random seed? I especially need that because I
need several *different* random values per pixel (I want to say, as many
as five); I handle this by simply adding a fixed value to the random
seed, which should be "good enough".
I don't have the exact formula handy (ask tomorrow if you want it), but
what I do is approximately:
- Run the rand() formula (a*s + b) on the X coordinate
- Initialize (unsigned short) s = with the X (after "salt") and Y
coordinates with the upper 16 bits XOR'd onto the lower 16.
- Call rand48 on s for Y % 37 iterations
- Call rand48 one last time, this time returning the result
What I found is that without the two flavors of 'salt', if I filled
every pixel with the straight-up results of rand48 with the seed
initialized as above, I got something that wasn't random in the
slightest (diagonal saw waves, in fact). With only one salt, it was
better, but still looked regular.
(sorry, .sig file is on the other computer)
More information about the kimageshop