I think the problem has two stages, first you assign a number of recrods, they can't be partial records by nature, so all get as much as they can to not exceed the total number and then some get 1 record more.
In the second stage you assign a percentage that's also rounded to nearest actual percentage. You accumulate an error in that phase, that will be assigned to the record with the highest percentage to cause the lowest relative error for it.
So in code:
Code:
* the input parameters are (for example):
recordcount = 11
usercount= 3
* this distributes records in stage 1 and what they mean in percentage in stage 2.
* result is stored into a cursor:
create cursor usershares( userno int, numrecords int, percentage int)
* stage 1, record or share numbers
numrecordsforall = int(recordcount/usercount)
lefftoverrecords = recordcount-usercount*numrecordsforall
for n=1 to usercount
? "user",n, "gets", numrecordsforall+iif(n<=lefftoverrecords,1,0), " records (shares)."
insert into usershares (userno, numrecords) values (n, numrecordsforall+iif(n<=lefftoverrecords,1,0))
endfor n
* stage 2, the percentages corresponding to the number of records:
update usershares set percentage = round(100*numrecords/recordcount,0)
calc sum(percentage) to overallpercentage
percentageerror = 100-overallpercentage
go 1
replace percentage with percentage+percentageerror
browse
In this example the records split up as 4,4,3 (4+4+3=11) and the percentages are 37,36,27. Of course 4 records are actually the same percentage, that is 4/11, or ca. 36.36%, 3 records are 27.27%, but the 1 percent error that results in first assigning 36,36 and 27 (36+36+27=99) the best way to make the least error is gve the 1% to one of the users having 36%.
The order in which you assign this can matter, as you talk about a customer and his family members, I'd need to know much more detals about what data you actually have, I'd also need to verify I have the right idea about each record being a share worth th same percentage. I think it is more complicated than you can present it in a forum post or thread. We'd need to make sure we understand the outset completely and correctly before making such calculations. So I won't give you any guarantee on that code to give you what you want, but you may learn from it, how to handle this.
In very short first make the best assignment by pure maths, and then spread the error, that's the strategy to follow. What's missing is to verify the end result to really sum to a) the right number of records and b) 100%. Even though in this case I'm sure it always will, there lurk corner cases that might lead to bad results, also unrealistic corner cases like 0 records. But they should be taken care of, too.
I bet there also are laws your customer didn't tell about or doesn't know himself. And I bet even if it's currently the case each record you assign has the same value/share/percentage, this could change in the future. So even if this is right, this is not a futureproof solution.
Chriss