1
0
Fork 0

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

This commit is contained in:
Christopher Browne 2016-02-06 19:42:08 -05:00
parent 73f14db8ad
commit fe1519de07

View file

@ -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,7 +144,12 @@ 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) {
/* 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 */
switch ((random_value ^ clockbyte) % 10) {
case 0: case 0:
register_code (KC_0); register_code (KC_0);
unregister_code (KC_0); unregister_code (KC_0);
@ -188,9 +195,12 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
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);