[erlang-questions] RNG algorithm choice for uniform natural numbers

Krzysztof Jurewicz krzysztof.jurewicz@REDACTED
Fri Aug 17 22:41:17 CEST 2018


> Have you tried to change line above to
>                     RandInt = rand:uniform(1 bsl 32),
> and not add 1 to RandInt below?
>
> To see if the problem you had was about the random number generator or in
> the surrounding code...

Let’s assume that we have 3 seats and the following voting results (in order):

A — 1 vote;
B — 1 vote;
C — 100 votes.

Following the simple algorithm, A has 1⁄102 chance of getting a seat. Let’s assume that A was lucky. Then we have 2 remaining seats and the following results remaining:

B — 1 vote;
C — 100 votes.

B has then 1⁄101 chance of getting a seat. Let’s assume that it was lucky. Then we have one remaining seat which goes to C. Final results:

A — 1 seat;
B — 1 seat;
C — 1 seat.

But according to quota property, C should get either 2 or 3 seats. This flaw is inherent to the simple apportionment algorithm and independent of the random number generator.



More information about the erlang-questions mailing list