diff --git a/comsoc/GenerateProfile.go b/comsoc/GenerateProfile.go new file mode 100644 index 0000000000000000000000000000000000000000..14f0871eeba1b49e6a0f62354cad6e707f324873 --- /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