get_rnd_text() for rumors and other stuff
Solve the uneven distribution situation that has been present for picking random rumors for a long time and for random engravings, epitaphs, and hallucinatory monster names since 3.6.0. This relies on the previous partial solution where short lines have been padded to a longer length. When that length is N and random seek lands in a long line of length L, retry if the position is in the first L-N characters. Put differently, it if takes more than N characters to reach the next newline, reject that random seek and try again. This effectively makes long lines behave as if they had the same length of N as the short lines have been padded to and when all lines are the same length, all entries have the same chance to be chosen.
This commit is contained in:
@@ -18,7 +18,7 @@ random_engraving(char *outbuf)
|
||||
/* a random engraving may come from the "rumors" file,
|
||||
or from the "engrave" file (formerly in an array here) */
|
||||
if (!rn2(4) || !(rumor = getrumor(0, outbuf, TRUE)) || !*rumor)
|
||||
(void) get_rnd_text(ENGRAVEFILE, outbuf, rn2);
|
||||
(void) get_rnd_text(ENGRAVEFILE, outbuf, rn2, MD_PAD_RUMORS);
|
||||
|
||||
wipeout_text(outbuf, (int) (strlen(outbuf) / 4), 0);
|
||||
return outbuf;
|
||||
@@ -1446,7 +1446,7 @@ make_grave(int x, int y, const char *str)
|
||||
/* Engrave the headstone */
|
||||
del_engr_at(x, y);
|
||||
if (!str)
|
||||
str = get_rnd_text(EPITAPHFILE, buf, rn2);
|
||||
str = get_rnd_text(EPITAPHFILE, buf, rn2, MD_PAD_RUMORS);
|
||||
make_engr_at(x, y, str, 0L, HEADSTONE);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user