chanceswitch

4 input logic switch every input has it's own chance to set output to high. the "off" parameter sets the chance of any incoming trigger to reset the output to off.
Author: Remco van der Most
License: BSD
Github: sss/logic/chanceswitch.axo

Inlets

bool32 input 1

bool32 input 2

bool32 i3

bool32 i4

Outlets

bool32 output

Parameters

frac32.u.map chance1

frac32.u.map chance2

frac32.u.map chance3

frac32.u.map chance4

frac32.u.map off

Declaration
bool trg[4];
bool gate[4];
bool use[4];
int B;
Control Rate
gate[0] = inlet_i1;
gate[1] = inlet_i2;
gate[2] = inlet_i3;
gate[3] = inlet_i4;
int32_t chance[4];
chance[0] = param_chance1;
chance[1] = param_chance2;
chance[2] = param_chance3;
chance[3] = param_chance4;
B = 0;
for (int i = 0; i < 4; i++) {
  if (gate[i] && !trg[i]) {
    trg[i] = 1;
    if (!use[i]) {

      if ((int32_t)(GenerateRandomNumber() >> 5) < chance[i]) {
        use[i] = 1;
      }
    } else {
      if ((int32_t)(GenerateRandomNumber() >> 5) < param_off) {
        use[i] = 0;
      }
    }
  } else if (!gate[i]) {
    trg[i] = 0;
  }
  // B=use[i]>B?1:B;
  B += use[i];
}
B = B & 1;

outlet_o = B;

Privacy

© 2024 Zrna Research