Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by EarthLaunch on Friday February 10, 2023 @12:41PM
(#34742985)
* * *
[ Parent
| on HN ]
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by jefftk on Friday February 10, 2023 @12:54PM
(#34743111)
In Python:
random.choices(population=['A', 'B', 'C', 'D'],
weights=[3, 2, 5, 7])
https://docs.python.org/3/library/random.html#random.choices
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by EarthLaunch on Friday February 10, 2023 @12:58PM
(#34743159)
Thank you very much! That led me to a JS clone[0].
Python has amazing math libraries. I use numjs[1] for everything, which is a port of numpy. I frequently wish I had use of Python's libraries.
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by freitzkriesler2 on Friday February 10, 2023 @12:59PM
(#34743185)
I've been pondering a way to implement a quantum random number generator into a game. Could this be useful at all?
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by EarthLaunch on Friday February 10, 2023 @10:31PM
(#34749319)
What is the general benefit to a quantum random number generator versus a regular one? Is it that it's more truly random, or has a better distribution, or?
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by rcme on Friday February 10, 2023 @01:01PM
(#34743222)
In your example, the weights need to add up to 100 to work correctly, right? The issue with the code in the article is that the weights did not add up to 1.
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by EarthLaunch on Friday February 10, 2023 @10:30PM
(#34749308)
Right, I'm using a percentage. The article's bug reminded me of this directly!
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by ryani on Friday February 10, 2023 @01:02PM
(#34743228)
Here's the standard algorithm for this problem
function weightedRandom(weight, outcomes){
var total = sum( weight );
var roll = Math.random()*total; // value in the range [0,total)
var seen = 0;
for(let i=0; i<weight.length; i++) {
seen += weight[i];
if(roll<seen)
return outcomes[i];
}
}
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by shadowgovt on Friday February 10, 2023 @01:06PM
(#34743297)
Statistics is actually pretty hard to get right, and it is the nature of the problem space that errors aren't immediately apparent unless one actually runs analytical regression on the algorithm to confirm it has the right "shape," which (a) can be time-consuming given the complexity of the algorithm and (b) doesn't tend to be part of unit tests because unit test doctrine is pathologically opposed to nondeterminism.
(This last pert is not an unsolvable problem, and in fact random algorithms should be unit tested. But it requires the right kind of unit testing).
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by nmca on Friday February 10, 2023 @01:37PM
(#34743768)
On occasion I have written a seeded large n statistical test that passes & the submitted with the seed fixed. I think this is the soundest approach, although it has a "your random number is 7" feel to it.
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by dekhn on Friday February 10, 2023 @03:55PM
(#34745707)
IIRC the other solution is to make a tree structure instead of a CDF. Can't remember if it's a good solution though.
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by arduinomancer on Friday February 10, 2023 @05:22PM
(#34746805)
Re:The Wi Flag -Turns out some players in Asheron's Call wer...
by EarthLaunch on Friday February 10, 2023 @10:40PM
(#34749363)
* * *