2022-01-01 09:35:06 -07:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "picker.h"
|
|
|
|
|
|
|
|
Picker::Picker() {
|
2024-06-09 21:53:19 -06:00
|
|
|
this->val = random(1, 256);
|
2022-01-01 09:35:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Picker::Pick(uint8_t likelihood) {
|
2024-06-09 21:53:19 -06:00
|
|
|
bool picked = false;
|
2022-01-01 09:35:06 -07:00
|
|
|
if ((val > 0) && (val <= likelihood)) {
|
2024-06-09 21:53:19 -06:00
|
|
|
picked = true;
|
2022-01-01 09:35:06 -07:00
|
|
|
}
|
|
|
|
val -= likelihood;
|
2024-06-09 21:53:19 -06:00
|
|
|
return picked;
|
2022-01-01 09:35:06 -07:00
|
|
|
}
|