Skip to content
Snippets Groups Projects
Commit 01e78215 authored by Gabrielle Van De Vijver's avatar Gabrielle Van De Vijver Committed by Balthazar Wilson
Browse files

fonction pour générer automatiquement des profils

parent be7b14e5
No related branches found
No related tags found
No related merge requests found
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment