]> git.pond.sub.org Git - empserver/commit
Fix tiny error in distribution of die rolls
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 19 Aug 2012 10:19:04 +0000 (12:19 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 8 May 2013 04:55:20 +0000 (06:55 +0200)
commitb5d8806eb1b08d7c99fdd376cc6cd69f8c002e71
treedf320cb170344cdcbf6b049647bd836460178e0c
parent54ddcd0f5a0723ed9901593cde8cd5b23ba0a8e3
Fix tiny error in distribution of die rolls

"random() % n" is sound only when n is a power of two.  The error is
hardly relevant in Empire, because random() yields 31 bits, and our n
are always much smaller than 2^31.  Fix it anyway.

Use smallest the 2^m >= n instead of n, and discard numbers exceeding
n.

Bonus: faster for me even in the worst case n = 2^m+1.

Like the recent change to damage(), this changes some of the server's
die rolls, only this time the effect is pretty pervasive.  Worse,
fairland now creates a completely different random map for the same
seed.  Update expected smoke test results accordingly.
src/lib/gen/chance.c
tests/fairland/fairland.out
tests/fairland/fairland.xdump
tests/fairland/newcap_script
tests/smoke/smoke.out
tests/smoke/smoke.xdump