Large amounts of psudo-random data

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
Post Reply
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4597
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Large amounts of psudo-random data

Post by Little stoned kiwi »

I'm making a landscape generator using Simplex Noise in WebGL.* The asset generation is being done in GLSL, the vector calculation and concurrent nature of the work should lend itself well to being done on the graphics card.
I'm stuck on how to produce the initial noise vectors with both randomness and re-producibility from the same initial seed number.
I'm familiar with the usual psudo-random generators that take their output as the next run's input but that's serial, I'd like it to be parallel so a point on a 2d grid can collect it's deterministic random information out of order.
As each compute stage will be grouped with like tasks there isn't a need to determine the number on demand. It will be calculated in a batch as quickly as possible, ideally on the graphics card in parallel, or generated somewhere else and loaded to the card. I suspect I can get away with low entropy as it will be shoved into vectors being used as noise.

I would totally appreciate hearing the creative out-of-the-box ideas and experiences you all have.


*What an I say? It's a learning experience.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4597
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Large amounts of psudo-random data

Post by Little stoned kiwi »

Code: Select all

float Noise(int x, int y, int random)
{
  int n = x + y * 57 + random * 131;
  n = (n<<13) ^ n;
  return (1.0f - ( (n * (n * n * 15731 + 789221) +
            1376312589)&0x7fffffff)* 0.000000000931322574615478515625f);
This might be worth a look at. The site I ...borrowed it from is using it to make a noise map for cloud generation. They use it with random generated outside the array population loops so nothing changes between iterations other than the x and y inputs.
No idea what's going on in there though.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Large amounts of psudo-random data

Post by Dio »

Right. All you need is a function that takes x and y input and combines those into a seed, and you can then use that seed to generate all the random numbers you need for that point. To further generalise, what you're doing here is to take a hash of the full set of keying parameters into a seed.

I would make sure that the hash function tries to mix the two as uniquely as possible across your range of x and y (the one below, for example, generates the same seed for x=57,y=0 and x=0,y=1, and that's pretty awful, and it's not even that fast a hash).
User avatar
Little stoned kiwi
Baaaaaa!
Baaaaaa!
Posts: 4597
Joined: Mon Oct 27, 2003 6:05 am 0
Location: Christchurch

Re: Large amounts of psudo-random data

Post by Little stoned kiwi »

Dio wrote:hash
Thanks Dio, I'll look into that. If the quality of the output's entropy starts with the range of it's input seed, that's limited by the small range of x and y. The random variable is really a map number.
I'm taken by the idea of sorting a pool to shuffle it some more, or some other method to shake the tree. I could generate a pool of data on the JavaScript side and send it to the graphics card in a buffer as it's the first step anyway (perhaps as vectors that are ready to use).
It would be rewarding to learn how to do it on the card, if only to learn more about what it's capable of.
If they think you're crude, go technical; if they think you're technical, go crude. I'm a very technical boy.
User avatar
Dio
Sheepie Whore
Sheepie Whore
Posts: 18887
Joined: Mon May 31, 2004 1:08 pm 0
Location: Newcastle UK

Re: Large amounts of psudo-random data

Post by Dio »

Well, the input state is small if it's just the map range, so the number of unique values that you can generate is small. But with a strong hash function, changing any single bit of the input on average changes a (pseudorandom) 50% of the bits of the output, so the seed is very strongly different even for tiny differences in the input.
Post Reply