Improve shuffling algorithm of connection list
PATCH 1/1 Improve shuffling algorithm of connection list
---
Improve shuffling algorithm of connection list
This patch implements the Fisher-Yates shuffle algorithm to ensure that all permutations of the connection target list are generated with equal probability, eliminating biases present in the previous shuffling method.
In the Fisher-Yates algorithm, there's only one way to obtain each permutation through these swaps, so all permutations occur with equal probability in theory.
Signed-off-by Hurukawa2121 <[email protected]...>
src/openvpn/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/init.c +2 -2
@@ -478,9 +478,9 @@ init_connection_list(struct context *c)if (c->options.remote_random) {int i; -for (i =0 ; i < l->len; ++i) +for (i = l->len -1 ; i >0 ; --i) { -const int j =get_random () % l->len; +const int j =get_random () % (i +1 );if (i != j) {struct connection_entry *tmp;
Signature · 1 line
2.39.3 (Apple Git-146)