Hi Rune,
From what you say below it sounds like a random number generator
would work fine, where you use the 3 or 4 integers as the seed,
and then call random.nextInt() to get your random hash. If the inputs
have too many bits for a single seed, then use more than one RNG
and combine their outputs in some way (e.g. add them), and then take
it modulo the required range.
Hope this helps.
Simon Lucas
From what you say below it sounds like a random number generator
would work fine, where you use the 3 or 4 integers as the seed,
and then call random.nextInt() to get your random hash.
Hi Rune,
I think it might be as simple as that.
e.g. – I’ve written this Java function to do a similar
thing to your texture example:
Where func(i,j) returns the intensity of pixel i,j
public int func(int i, int j) {
Random r = new Random(i * j);
int x = r.nextInt() % 256;
return Math.abs(x);
}
Image below (not sure whether this will be posted)
It looks fine, I think.
Note: the details of the RNG are important,
and it’s usually much safer to take the low order
bits (which I did by doing % 256) rather than the high order
ones which you did implicitly by calling nextDouble
Cheers,
Simon
this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1);
Hi Rune,
Using the Java RNG, taking the higher-order bits (via calls to nextDouble) makes a big difference:
(produced with:
public int func(int i, int j) {
Random r = new Random(i * j);
int x = (int) (r.nextDouble() * 256); // note: r.nextInt(256) produces the same banded pattern
return Math.abs(x); // Math.abs no longer necessary in this version
}
Regarding the mirror image in line i=j, yes, that’s right, but for a given task that may or may not be a problem.
And on closer inspection, there are identifiable patterns in the “random texture” I posted yesterday.
Do you have an objective measure of
how fit for *your* purpose one of these hashing functions is?
Cheers,
Simon
From: procedur...@googlegroups.com [mailto:procedur...@googlegroups.com]
On Behalf Of Rune Skovbo Johansen
Sent: 04 September 2012 08:59
To: procedur...@googlegroups.com
Subject: Re: [pcg] Good random hash function?
Hi Simon,
That's interesting. I tried to first replicate your code exactly, but I got a distinct pattern. I looked into the implementations of Random in Java versus C# and noted that C# takes the given seed as it, while Java modifies the given seed with this formula:
this.seed = (seed ^ 0x5DEECE66DL) & ((1L << 48) - 1);
Once I added the same modification to the seed in my C# code I got results comparable to yours.
About using the low order bits; I found it to not make a difference. My original code gave the same kind of patterns when I used .Next() % 256 (.Next() returns a positive int in C#). And with the seed modification, it gave the same apparent randomness regardless
of whether I used Next() % 256 or NextDouble().
So it seems like the randomness here is solely down to the seed modification done with the above formula, and although it looks random in the texture you posted, I'm not sure it's really all that random.
If you try to look at the values generated on the line from coord (1, 0) to coord (1, 65536) you'll see distinct patterns. (I created a 256x256 texture with the random values in that line to verify by changing i*j to i+256*j.)
On a side note, basing the seed on i*j creates a diagonal mirror axis and also creates the same seed for any coord where either i or j is 0.
Cheers,
Rune
On Monday, September 3, 2012 11:37:06 PM UTC+2, Lucas, Simon M wrote:
Hi Rune,
I think it might be as simple as that.
e.g. – I’ve written this Java function to do a similar
thing to your texture example:
Where func(i,j) returns the intensity of pixel i,j
public int func(int i, int j) {
Random r = new Random(i * j);
int x = r.nextInt() % 256;
return Math.abs(x);
}
Image below (not sure whether this will be posted)
It looks fine, I think.
Regarding the mirror image in line i=j, yes, that’s right, but for a given task that may or may not be a problem.And on closer inspection, there are identifiable patterns in the “random texture” I posted yesterday.
Do you have an objective measure of how fit for *your* purpose one of these hashing functions is?
My instinct would be to use multidimensional simplex noise.
On the other hand, it might be worth looking into what games like
Noctis and Minecraft use (although whether that information is
available I don't know).
Hi Rune, Adam,
So far we’ve had some fun looking at the textures
generated by various methods,
but I think it would be also be interesting to experiment
with quantitative measures of hash quality.
Two components to it:
· an even spread of output values over the set of inputs,
· some measure of non-locality (at least, if the measure
is to correlate with the subjective ratings we’re been using
so far).
Adam, your colour image looks pretty random, but I thought I could
see at least one smiley faces in it! Also, by using 24 bit output, you’re reducing
the probability of collisions (in fact, going from a 20 bit input to
a 24 bit output it would be possible to have no collisions; have you looked at
the 8 bit grey-scale version?).
--
---
You received this message because you are subscribed to the Google Groups "Procedural Content Generation" group.
To unsubscribe from this group and stop receiving emails from it, send an email to proceduralcont...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.