From 5756c775a22534d689dccc5e9db92409fea09919 Mon Sep 17 00:00:00 2001 From: Moncef STITI <moncef.stiti@etu.u-pec.fr> Date: Tue, 3 Dec 2024 18:52:56 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20de=20la=20g=C3=A9n=C3=A9ration=20d?= =?UTF-8?q?e=20montants=20de=20transfert=20et=20am=C3=A9lioration=20de=20l?= =?UTF-8?q?a=20gestion=20des=20temporisations=20al=C3=A9atoires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Secured/secured_transaction.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Secured/secured_transaction.c b/Secured/secured_transaction.c index b8e70b0..0ba3338 100644 --- a/Secured/secured_transaction.c +++ b/Secured/secured_transaction.c @@ -63,7 +63,7 @@ void perform_transaction(int fd, int account_count) { // Calculer un montant aléatoire à transférer (max 20% du solde source) int max_transfer = from_balance / 5; if (max_transfer > 0) { - int transfer_amount = rand() % max_transfer; + int transfer_amount = rand() % max_transfer + 1; // Effectuer la transaction from_balance -= transfer_amount; @@ -89,7 +89,7 @@ void process_transactions(int transactions, int account_count) { for (int i = 0; i < transactions; i++) { perform_transaction(fd, account_count); - //usleep(rand() % 100000); // Temporisation aléatoire + usleep(rand() % 100000); // Temporisation aléatoire } close(fd); @@ -127,7 +127,8 @@ int main(int argc, char *argv[]) { int num_processes = atoi(argv[1]); int transactions_per_process = atoi(argv[2]); - srand(time(NULL)); + unsigned int seed = getpid() ^ time(NULL); + int random_value = rand_r(&seed); // Calcul du solde total initial int initial_balance = calculate_total_balance();