, , . .
, M {0, ..., N-1} i i. p(i, M, N). , , Latex, p; , .
p(0, M, N), , M N . (.. 0...N-1) ; , , . .
MCN M N. MCN-1 . ( M - N-1, M - , ). , M-1CN-1 (.. M-1 - N-1 -set, ).
MCN; C.
, p(0, M, N) - M-1CN-1/MCN. MCN = N!/(M!*(N-M)!), M/N. , if M == N, 1 (M N ).
, , , . , , , , . , , :
w(x, y) => true with probability X / Y; otherwise false.
w , .
:
Generate a random M-selection from the set 0...N-1
Parameters: M, N
Set i = 0
while M > 0:
if w(M, N):
output i
M = M - 1
N = N - 1
i = i + 1
, , , :
output i M , M, while , M 0M N, , M . - , M == N, , 0.i , N , 0...N-1. , ; N-1 i, . , , .
O(N+M), O(N). N , , , , .