use system randomness by default unless overridden

This commit is contained in:
Martin Michelsen
2024-02-23 23:50:03 -08:00
parent 7dc5a02a83
commit 294d180e68
22 changed files with 148 additions and 106 deletions
+4 -4
View File
@@ -298,22 +298,22 @@ struct ProbabilityTable {
return this->items[--this->count];
}
void shuffle(PSOLFGEncryption& random_crypt) {
void shuffle(std::shared_ptr<PSOLFGEncryption> opt_rand_crypt) {
for (size_t z = 1; z < this->count; z++) {
size_t other_z = random_crypt.next() % (z + 1);
size_t other_z = random_from_optional_crypt(opt_rand_crypt) % (z + 1);
ItemT t = this->items[z];
this->items[z] = this->items[other_z];
this->items[other_z] = t;
}
}
ItemT sample(PSOLFGEncryption& random_crypt) const {
ItemT sample(std::shared_ptr<PSOLFGEncryption> opt_rand_crypt) const {
if (this->count == 0) {
throw std::runtime_error("sample from empty probability table");
} else if (this->count == 1) {
return this->items[0];
} else {
return this->items[random_crypt.next() % this->count];
return this->items[random_from_optional_crypt(opt_rand_crypt) % this->count];
}
}
};