MCPcopy Index your code
hub / github.com/NetHack/NetHack / randomkey

Function randomkey

src/cmd.c:3516–3578  ·  view source on GitHub ↗

choose a random character, biased towards movement commands, primarily for debug-fuzzer testing */

Source from the content-addressed store, hash-verified

3514/* choose a random character, biased towards movement commands, primarily
3515 for debug-fuzzer testing */
3516char
3517randomkey(void)
3518{
3519 static unsigned i = 0;
3520 static char last_c = '\0';
3521 char c;
3522
3523 /* give ^A and ^P a high probability of being repeated */
3524 if ((last_c == C('a') || last_c == C('p'))
3525 && program_state.input_state == commandInp && rn2(5))
3526 return last_c;
3527
3528 switch (rn2(16)) {
3529 default:
3530 c = '\033';
3531 break;
3532 case 0:
3533 c = '\n';
3534 break;
3535 case 1:
3536 case 2:
3537 case 3:
3538 case 4:
3539 c = (char) rn1('~' - ' ' + 1, ' ');
3540 break;
3541 case 5:
3542 c = (char) (rn2(2) ? '\t' : ' ');
3543 break;
3544 case 6:
3545 c = (char) rn1('z' - 'a' + 1, 'a');
3546 break;
3547 case 7:
3548 c = (char) rn1('Z' - 'A' + 1, 'A');
3549 break;
3550 case 8:
3551 c = extcmdlist[i++ % SIZE(extcmdlist)].key;
3552 break;
3553 case 9:
3554 c = '#';
3555 break;
3556 case 10:
3557 case 11:
3558 case 12:
3559 {
3560 int d = rn2(N_DIRS);
3561 int m = rn2(7) ? MV_WALK : (!rn2(3) ? MV_RUSH : MV_RUN);
3562
3563 c = cmd_from_dir(d, m);
3564 }
3565 break;
3566 case 13:
3567 c = (char) rn1('9' - '0' + 1, '0');
3568 break;
3569 case 14:
3570 /* any char, but avoid '\0' because it's used for mouse click */
3571 c = (char) rnd(iflags.wc_eight_bit_input ? 255 : 127);
3572 break;
3573 }

Callers 12

tty_nhgetchFunction · 0.85
NHEditHookWndProcFunction · 0.85
onMSNHCommandFunction · 0.85
FuzzTimerProcFunction · 0.85
NHMenuListWndProcFunction · 0.85
NHMenuTextWndProcFunction · 0.85
curses_getchFunction · 0.85
tgetchFunction · 0.85
console_poskeyFunction · 0.85
pgetcharFunction · 0.85
random_responseFunction · 0.85
readchar_coreFunction · 0.85

Calls 3

rn2Function · 0.85
cmd_from_dirFunction · 0.85
rndFunction · 0.85

Tested by

no test coverage detected