Skip to content

Conversation

mdbrnowski
Copy link
Contributor

@mdbrnowski mdbrnowski commented Aug 13, 2025

Before this change, the code below gives different outcomes (despite random.seed()) because set (and thus Instance) is unordered. After the change, it always produces the same result.

import random
from pabutools.election.instance import get_random_instance
from pabutools.election.profile import get_random_approval_profile

random.seed(42)
instance = get_random_instance(3, 1, 10)
profile = get_random_approval_profile(instance, 10)
print(profile)

One could instead add sorted() in get_random_approval_ballot(), but this could negatively impact performance.
Therefore, I decided to leave get_random_approval_ballot() non-deterministic by default (unless, of course, the user passes an ordered Iterable as an argument).

@Simon-Rey Simon-Rey merged commit 09473fd into COMSOC-Community:main Aug 18, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants