Add in XOR of lowest 8 bits of system timer to encourage more randomness of the digits/letters chosen

pull/136/head
Christopher Browne 9 years ago
parent 73f14db8ad
commit fe1519de07

@ -118,6 +118,8 @@ static uint16_t random_value = 157;
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{ {
uint8_t clockbyte=0;
clockbyte = TCNT1 % 256;
// MACRODOWN only works in this function // MACRODOWN only works in this function
switch(id) { switch(id) {
case M_LED: case M_LED:
@ -142,160 +144,168 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
a numeric digit chosen at random */ a numeric digit chosen at random */
random_value = ((random_value + randadd) * randmul) % randmod; random_value = ((random_value + randadd) * randmul) % randmod;
if (record->event.pressed) if (record->event.pressed)
switch(random_value % 10) {
case 0: /* Here, we mix the LCRNG with low bits from one of the system
register_code (KC_0); clocks via XOR in the theory that this may be more random
unregister_code (KC_0); than either separately */
break;
case 1: switch ((random_value ^ clockbyte) % 10) {
register_code (KC_1); case 0:
unregister_code (KC_1); register_code (KC_0);
break; unregister_code (KC_0);
case 2: break;
register_code (KC_2); case 1:
unregister_code (KC_2); register_code (KC_1);
break; unregister_code (KC_1);
case 3: break;
register_code (KC_3); case 2:
unregister_code (KC_3); register_code (KC_2);
break; unregister_code (KC_2);
case 4: break;
register_code (KC_4); case 3:
unregister_code (KC_4); register_code (KC_3);
break; unregister_code (KC_3);
case 5: break;
register_code (KC_5); case 4:
unregister_code (KC_5); register_code (KC_4);
break; unregister_code (KC_4);
case 6: break;
register_code (KC_6); case 5:
unregister_code (KC_6); register_code (KC_5);
break; unregister_code (KC_5);
case 7: break;
register_code (KC_7); case 6:
unregister_code (KC_7); register_code (KC_6);
break; unregister_code (KC_6);
case 8: break;
register_code (KC_8); case 7:
unregister_code (KC_8); register_code (KC_7);
break; unregister_code (KC_7);
case 9: break;
register_code (KC_9); case 8:
unregister_code (KC_9); register_code (KC_8);
break; unregister_code (KC_8);
} break;
case 9:
register_code (KC_9);
unregister_code (KC_9);
break;
}
break; break;
case M_RANDLETTER: case M_RANDLETTER:
/* Generate, based on random number generator, a keystroke for /* Generate, based on random number generator, a keystroke for
a letter chosen at random */ a letter chosen at random */
/* Here, we mix the LCRNG with low bits from one of the system
clocks via XOR in the theory that this may be more random
than either separately */
random_value = ((random_value + randadd) * randmul) % randmod; random_value = ((random_value + randadd) * randmul) % randmod;
if (record->event.pressed) if (record->event.pressed)
switch(random_value % 26) { switch((random_value ^ clockbyte) % 26) {
case 0: case 0:
register_code(KC_A); register_code(KC_A);
unregister_code(KC_A); unregister_code(KC_A);
break; break;
case 1: case 1:
register_code(KC_B); register_code(KC_B);
unregister_code(KC_B); unregister_code(KC_B);
break; break;
case 2: case 2:
register_code(KC_C); register_code(KC_C);
unregister_code(KC_C); unregister_code(KC_C);
break; break;
case 3: case 3:
register_code(KC_D); register_code(KC_D);
unregister_code(KC_D); unregister_code(KC_D);
break; break;
case 4: case 4:
register_code(KC_E); register_code(KC_E);
unregister_code(KC_E); unregister_code(KC_E);
break; break;
case 5: case 5:
register_code(KC_F); register_code(KC_F);
unregister_code(KC_F); unregister_code(KC_F);
break; break;
case 6: case 6:
register_code(KC_G); register_code(KC_G);
unregister_code(KC_G); unregister_code(KC_G);
break; break;
case 7: case 7:
register_code(KC_H); register_code(KC_H);
unregister_code(KC_H); unregister_code(KC_H);
break; break;
case 8: case 8:
register_code(KC_I); register_code(KC_I);
unregister_code(KC_I); unregister_code(KC_I);
break; break;
case 9: case 9:
register_code(KC_J); register_code(KC_J);
unregister_code(KC_J); unregister_code(KC_J);
break; break;
case 10: case 10:
register_code(KC_K); register_code(KC_K);
unregister_code(KC_K); unregister_code(KC_K);
break; break;
case 11: case 11:
register_code(KC_L); register_code(KC_L);
unregister_code(KC_L); unregister_code(KC_L);
break; break;
case 12: case 12:
register_code(KC_M); register_code(KC_M);
unregister_code(KC_M); unregister_code(KC_M);
break; break;
case 13: case 13:
register_code(KC_N); register_code(KC_N);
unregister_code(KC_N); unregister_code(KC_N);
break; break;
case 14: case 14:
register_code(KC_O); register_code(KC_O);
unregister_code(KC_O); unregister_code(KC_O);
break; break;
case 15: case 15:
register_code(KC_P); register_code(KC_P);
unregister_code(KC_P); unregister_code(KC_P);
break; break;
case 16: case 16:
register_code(KC_Q); register_code(KC_Q);
unregister_code(KC_Q); unregister_code(KC_Q);
break; break;
case 17: case 17:
register_code(KC_R); register_code(KC_R);
unregister_code(KC_R); unregister_code(KC_R);
break; break;
case 18: case 18:
register_code(KC_S); register_code(KC_S);
unregister_code(KC_S); unregister_code(KC_S);
break; break;
case 19: case 19:
register_code(KC_T); register_code(KC_T);
unregister_code(KC_T); unregister_code(KC_T);
break; break;
case 20: case 20:
register_code(KC_U); register_code(KC_U);
unregister_code(KC_U); unregister_code(KC_U);
break; break;
case 21: case 21:
register_code(KC_V); register_code(KC_V);
unregister_code(KC_V); unregister_code(KC_V);
break; break;
case 22: case 22:
register_code(KC_W); register_code(KC_W);
unregister_code(KC_W); unregister_code(KC_W);
break; break;
case 23: case 23:
register_code(KC_X); register_code(KC_X);
unregister_code(KC_X); unregister_code(KC_X);
break; break;
case 24: case 24:
register_code(KC_Y); register_code(KC_Y);
unregister_code(KC_Y); unregister_code(KC_Y);
break; break;
case 25: case 25:
register_code(KC_Z); register_code(KC_Z);
unregister_code(KC_Z); unregister_code(KC_Z);
break; break;
} }
break; break;
} }
return MACRO_NONE; return MACRO_NONE;

Loading…
Cancel
Save