generate-random-client-id

gabbapeople/sim7020/generate-random-client-id

Generates a random CAP-sized clientID string of Latin characters from "a" to "z".
generate-random-client-id
@/generate-random-client-id
Generates a random CAP-sized clientID string of Latin characters from "a" to "z".
CAPnumber
The capacity of the Client ID string to be generated.
GENpulse
Triggers new Client ID generation.
generate-random-client-id
CAP
GEN
CID
DONE
DONEpulse
Fires when the Client ID is generated.
CIDstring
Random geerated Client ID.
To use the node in your project you should have the gabbapeople/sim7020 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    char* id;
    size_t cap;
    CStringView view;
};

{{ GENERATED_CODE }}

uint8_t getRandomCharNum(uint8_t low, uint8_t high){
	return (rand() % (high - low + 1)) + low;
}

void evaluate(Context ctx) {

  auto state = getState(ctx);

   if (isSettingUp()) {
    state->cap = getValue<input_CAP>(ctx);
    state->id = new char[state->cap + 1];
    memset(state->id, '\0', state->cap + 1);
    state->view = CStringView(state->id);
  }

  if (isInputDirty<input_GEN>(ctx)){
    memset(state->id, '\0', state->cap + 1);


    for (uint8_t i = 0; i < state->cap; i++){
      state->id[i] = (char)(getRandomCharNum(97,122));
    }

    emitValue<output_CID>(ctx, XString(&state->view));
    emitValue<output_DONE>(ctx, 1);
  }
}