Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"09-06-10 - WeightedDecayRand"

12 Comments -

1 – 12 of 12
Blogger Unknown said...

I found that when people ask for a random events, what they really want is a permutation of those events happening.

So a 1/10 loot drop becomes (literally) one loop drop for every 10 - not an independent 10% chance with each drop.

September 9, 2010 at 6:47 PM

Blogger Unknown said...

"In particular the biggest difference is that real random numbers can be very bunchy, which almost always feels bad to the player. "

This is why I come here. To read intelligent thoughts. Feels like founding a clear water fountain in the Fallout3 wasteland !

September 9, 2010 at 7:44 PM

Blogger won3d said...

The formal, signal-processing way to think about it is:

http://en.wikipedia.org/wiki/Noise_shaping

September 9, 2010 at 9:23 PM

Blogger Unknown said...

A similar approach is to say:

I want this to happen 1 in every 10 times. Generate a random number n, from 1 to 10. Return true on the nth time. Return false the other 9 times. After the 10th try, generate a new random number.

Thus, the special effect on a weapon or such activates 1 in 10 times, always, but he can't predict WHEN it'll happen (for the most part).

September 10, 2010 at 9:25 AM

Blogger Doug said...

I built a simpler system (mostly math based) a few years back that is based on what Ian said above. The basic concept is that with a 1/5 drop rate, players really expect the first kill to be 1/5 and if they fail, the second to be 1/4 and if they fail again, the third to be 1/3. If you set up your drop rates in fraction form, remove the numerator from the denominator for each attempt, and add the initial denominator to the current denominator on each success you will have a (roughly) guaranteed 1 success for every 5 attempts. It is even easy to scale down, guaranteeing 2 successes for 10 attempts (50% power) or 20 successes for 100 attempts (5% power).

There are some more little fiddly things that need to be handled but the implementation is cheap both in storage and processing and is scalable.

Relevant posts from my since abandoned blog:

http://designdeeply.blogspot.com/2006/09/swayed-random-number-generation.html

http://designdeeply.blogspot.com/2006/10/swayed-random-number-implementation.html

September 10, 2010 at 11:50 AM

Blogger cbloom said...

Yeah, that's permutation as Ian mentioned. Permutation is a good tool to have in the toolbox.

September 10, 2010 at 11:53 AM

Blogger cbloom said...

That was @Quantum

September 10, 2010 at 11:55 AM

Anonymous Anonymous said...

permutation is a bit subtle to do well; if you just use Quantum's naive implementation, you can still get 2-in-a-row, although it only happens 1 in 1000 times (100 sets of 10), and you can get 18 in a row of misses (also 1 in 100 sets of 10).

If those happen to be acceptable rates for those events, then you can use the naive solution, but most likely you don't want that.

The non-binary cases are much more interesting and overt to talk about. If you have 10 voice tracks you can play in reaction to event E, and you always have to play them, and you think you want to play them at random...

Zeroeth solution: at each event, just play the next recording in order, and then repeat when you run out. "But that's not random!"

First solution: pick one at random, it has repeats and sounds dumb

Second solution: some complicated scheme where you deprioritize recent ones. Still repeats more than you want, or too hard to tune.

Third solution: randomly permute the 10 elements, do 10 events, randomly permute again. Problem: can still get repeats across premutation boundaries.

Fourth solution: Randomly choose one permutation once. Just play that permutation over and over forever, guaranteeing it's always 9 events until you hear the same one again.

Fifth solution: Randomize the order offline, so everyone always gets the exact same "random" order. This is identical to the 0th solution.

Problem with four and five: people may notice that the order repeats, that they'll always hear a given one after another given one. I've never heard that complaint, but that seems to be the only reason to move onto the next solution (although plenty of people have moved onto it):

Sixth solution: pick a random permutation. Play through it. Now, do small local swaps on the permutation to build the new permutation, guaranteeing that each event is, say, no less than 7 or 8 distant and no more than 12 or 13 distant from their previous usage.

Note that the last solution is very similar in behavior to one where you track "how long has it been since I last used this one" and then you only choose from the ones that have been at least 7 ago and with increasing priority as they get above 10.

I've definitely heard of people doing things along the line of these last two solutions.

As mentioned, I'm not sure why.

September 10, 2010 at 4:07 PM

Blogger cbloom said...

"Problem with four and five: people may notice that the order repeats, that they'll always hear a given one after another given one. I've never heard that complaint,"

Yeah I certainly notice this and there are plenty of cases where it's definitely not okay. Like maybe it's okay for dialogue sequences (because that's sort of weird and gamey anyway, so it's okay if it's just a sequence), but if you used it for gun shot or footstep sounds, the pattern would be very obvious.

"Second solution: some complicated scheme where you deprioritize recent ones. Still repeats more than you want, or too hard to tune."

This is what I propose here; it's really not that complicated and has no disadvantages that I know of (other than yes, being slightly unintuitive to tweak; probably that could be fixed by exposing the tweak parameters in a more designer-friendly way and doing some math to convert).

I think basically all other options have disadvantages or are harder to tweak and implement. (eg. the complicated permutation that you suggest at the end could be made equivalent of course but seems much harder to get right)

September 10, 2010 at 4:42 PM

Blogger Steve said...

What you want is a Poisson Distribution.

September 15, 2010 at 9:14 AM

Blogger cbloom said...

I hope that's a joke.

September 15, 2010 at 9:20 AM

Blogger Unknown said...

Very interesting. I will implement it in my fighting engine. You can follow me at http://kokusaifightingengine.blogspot.com/

October 6, 2010 at 1:24 AM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.