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:
@@ -2204,7 +2204,7 @@ bogusmon(char *buf, char *code)
|
||||
if (code)
|
||||
*code = '\0';
|
||||
/* might fail (return empty buf[]) if the file isn't available */
|
||||
get_rnd_text(BOGUSMONFILE, buf, rn2_on_display_rng);
|
||||
get_rnd_text(BOGUSMONFILE, buf, rn2_on_display_rng, MD_PAD_BOGONS);
|
||||
if (!*mnam) {
|
||||
Strcpy(buf, "bogon");
|
||||
} else if (index(bogon_codes, *mnam)) { /* strip prefix if present */
|
||||
|
||||
Reference in New Issue
Block a user