PDA

View Full Version : clustering random values



stib
02-02-2008, 10:53 PM
I was working on a script where I wanted to create some random values that clustered towards the centre. After a bit of fiddling I came up with something I'm proud of, so I thought I'd share



RandomValue = random(min, max)*pow((random(0,1), clusterAmount))


If you raise a random value by an exponent the graph of the probabilities looks like the graph of that exponent (I can't prove this, I just figured it out myself). Problem is that pow(random(-1, 1),2) only ever returns positive values. So I take the original random number and then multiply it by the exponentialated (what's the correct term for something that has been raise to a higher power?) random number you get nice clustering random numbers.

Of course you could go all clever on me and use proper gaussian random numbers, which I think involves using a sin curve as your distribution, but this is cheap and cheerful, and allows you to set the amount of clustering incrementally.

I'd like to hear any comments. I've probably just re-invented the centrally pivoted rotating device, but I was chuffed to get it to work.

stib
02-03-2008, 08:22 AM
those need to be float values in the second random number so it should be

RandomValue = random(min, max)*pow((random(0.0,1.0), clusterAmount))

Doesn't seem to be working as well today. I fixed one bug and it broke another bit.