// create nPeople / 2 memberOf associations
for (int i = 0; i < nPeople / 2; i++) {
int rand1 = getRandom(0, nPeople - 1);
PersonEntity person = db.getPeople().get(rand1);
int rand2 = getRandom(0, nOrganizations - 1);
OrganizationEntity organization = db.getOrganizations().get(rand2);
while (organization.getMembers().contains(person)) {
rand1 = getRandom(0, nPeople - 1);
person = db.getPeople().get(rand1);
}
organization.addMember(person);
person.addRelatedOrganization(organization);
}
}