From 2e2dbc082b25383c865d53ea09f641f6b9e57ea1 Mon Sep 17 00:00:00 2001 From: Gabrielle van de Vijver <gabrielle.van-de-vijver@etu.utc.fr> Date: Sun, 1 Oct 2023 18:12:01 +0200 Subject: [PATCH] =?UTF-8?q?fonction=20pour=20g=C3=A9n=C3=A9rer=20automatiq?= =?UTF-8?q?uement=20des=20profils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comsoc/GenerateProfile.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 comsoc/GenerateProfile.go diff --git a/comsoc/GenerateProfile.go b/comsoc/GenerateProfile.go new file mode 100644 index 0000000..14f0871 --- /dev/null +++ b/comsoc/GenerateProfile.go @@ -0,0 +1,39 @@ +package comsoc + +import ( + "fmt" + "math/rand" + "time" +) + +func GenerateProfile(nVoters int, nAlts int) { + // Initialisation du profil + profil := make([][]Alternative, nVoters) + for i := range profil { + profil[i] = make([]Alternative, nAlts) + } + + // Définition des alternatives + values := make([]Alternative, nAlts) + for i := range values { + values[i] = Alternative(i + 1) + } + + // Remplissage du profil avec des permutations différentes à chaque rang + rand.Seed(time.Now().UnixNano()) + for i := range profil { + // Mélange les valeurs pour chaque ligne + permutation := make([]Alternative, len(values)) + copy(permutation, values) + rand.Shuffle(len(permutation), func(i, j int) { + permutation[i], permutation[j] = permutation[j], permutation[i] + }) + + // Remplit la ligne avec la permutation + copy(profil[i], permutation) + } + + for _, row := range profil { + fmt.Println(row) + } +} \ No newline at end of file -- GitLab