wooby

gay dog

welcome to dog !!
gay transfemme nerd
over 21
please don't follow if you're under 18
avi 🎨: @VCRStatic


discord
@wooby
matrix
@woobyrubes:matrix.org
website
ruby.gay/

what's a good way of notating weight with regards to random events? like, if i wanted something to happen 10 times more than something else. i think it might be nice to do something like

[ 
    { weight: 10, event: () => abc() },
    { weight: 1, event: () => xyz() },
]

but maybe there's better ways? maybe everything should be a percent/100?


You must log in to comment.

in reply to @wooby's post:

i tend to agree; i guess it makes it a little more computationally expensive but if it's a set list there's no reason you couldn't just cache the chances as decimals anyways

aesthetically, i would rather see whole numbers than decimals in a big configuration object! and i think it's easier to edit than percentages too, since those need to always sum to exactly 1.

computationally, i think the fastest way to get a weighted random element like this is to do a binary search by rng (assuming it's in [0, 1)) times the sum of the weights? you'd need to fixup the table on bootup to have the start and end of each weight interval, but that's easy (sum of all previous weights, then that sum + the current weight). and of course, if the table is small, then linear search is also fine!

excellent nerd snipe :host-stare:

Archipelago's weighted meta-randomization options work a lot like yours, although more arbitrary and opaque, tbh. Once you (or whoever is looking at the system) understands the weighting system, I do think it's more intuitive than percentages, especially if you keep everything relative to a baseline (unlike archipelago).