Add in XOR of lowest 8 bits of system timer to encourage more randomness of the digits/letters chosen
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)
|
||||
{
|
||||
uint8_t clockbyte=0;
|
||||
clockbyte = TCNT1 % 256;
|
||||
// MACRODOWN only works in this function
|
||||
switch(id) {
|
||||
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 */
|
||||
random_value = ((random_value + randadd) * randmul) % randmod;
|
||||
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:
|
||||
register_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:
|
||||
/* Generate, based on random number generator, a keystroke for
|
||||
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;
|
||||
if (record->event.pressed)
|
||||
switch(random_value % 26) {
|
||||
switch((random_value ^ clockbyte) % 26) {
|
||||
case 0:
|
||||
register_code(KC_A);
|
||||
unregister_code(KC_A);
|
||||
|
|
Loading…
Reference in New Issue