Skip to content

Commit

Permalink
Randomise ballot order
Browse files Browse the repository at this point in the history
Closes #11
  • Loading branch information
codemicro committed Oct 29, 2023
1 parent 94ecfc0 commit ff1d3b5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/httpcore/endpoints_elections.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/mattn/go-sqlite3"
"log/slog"
"math/rand"
"sort"
)

func (endpoints) apiListElections(ctx *fiber.Ctx) error {
Expand Down Expand Up @@ -118,6 +120,11 @@ func (endpoints) apiGetActiveElectionInformation(ctx *fiber.Ctx) error {
return fmt.Errorf("apiGetActiveElectionInformation commit tx: %w", err)
}

// randomise ballot order
sort.Slice(ballot, func(_, _ int) bool {
return rand.Intn(2) == 0
})

var response = struct {
Election *database.Election `json:"election"`
Ballot []*database.BallotEntry `json:"ballot"`
Expand Down

0 comments on commit ff1d3b5

Please sign in to comment.