- Joined
- Mar 24, 2014
- Messages
- 579
- Reaction score
- 219
- First Language
- English
- Primarily Uses
- RMVXA
Just to get our definitions down, by buffering, I mean resistance to change.
While working on an actor generator script I realized that the randomization of certain
stats would be too varied on an actor by actor bases. I did come up with a way to remedy
this problem, but it's way too performance intensive to be a viable solution. Here's what I mean:
Let's say we want the actor's maximum level to be randomized.
actor.max_level = 1 + rand(98)
This is too random. There's an equal chance for the actor to land on any given level.
I want the middle value, 50, to be the most likely level.
We could do something like this:
actor.max_level = 20 + rand(60)
or this:
actor.max_level = Random.new.rand(20..80)
but its all just as random as before with some potential values excluded.
I want an actor's max level to be more likely to land on 50, but still have the potential
to deviate to very low or high values (just a lot less likely. I came up with this:
buffer = 100 # higher values increase resistance to change.
actor.max_level = Array.new(buffer){Random.new.rand(1..99)}.mean.round.to_i
It basically just creates an array of potential outcomes and returns the average value.
The higher the buffer, the less deviation from the average value. (Also lowers performance)
It works, but the performance is terrible. I'm looking for an alternate, performance friendly, solution.
While working on an actor generator script I realized that the randomization of certain
stats would be too varied on an actor by actor bases. I did come up with a way to remedy
this problem, but it's way too performance intensive to be a viable solution. Here's what I mean:
Let's say we want the actor's maximum level to be randomized.
actor.max_level = 1 + rand(98)
This is too random. There's an equal chance for the actor to land on any given level.
I want the middle value, 50, to be the most likely level.
We could do something like this:
actor.max_level = 20 + rand(60)
or this:
actor.max_level = Random.new.rand(20..80)
but its all just as random as before with some potential values excluded.
I want an actor's max level to be more likely to land on 50, but still have the potential
to deviate to very low or high values (just a lot less likely. I came up with this:
Code:
#==============================================================================
# ** Array
#------------------------------------------------------------------------------
# This class handles arrays.
#==============================================================================
class Array
#--------------------------------------------------------------------------
# * Sum of Array Elements
#--------------------------------------------------------------------------
def sum; inject(nil) {|sum, x| sum ? sum + x : x } end
#--------------------------------------------------------------------------
# * Mean of Array Elements
#--------------------------------------------------------------------------
def mean; sum / size end
end
actor.max_level = Array.new(buffer){Random.new.rand(1..99)}.mean.round.to_i
It basically just creates an array of potential outcomes and returns the average value.
The higher the buffer, the less deviation from the average value. (Also lowers performance)
It works, but the performance is terrible. I'm looking for an alternate, performance friendly, solution.
