标签:
1 //Algorithm S 2 intialize set S to empty 3 Size := 0 4 while Size < M do 5 T := RandInt(1, N) 6 if T is not in S then 7 insert T in S 8 Size := Size + 1
1 //Algorithm F1 2 funciton Sample(M, N) 3 if M = 0 then 4 return the empty set 5 else 6 S := Sample(M - 1, N - 1) 7 T := RandInt(1, N) 8 if T is not in S then 9 insert T in S 10 else 11 insert N in S 12 return S
1 //Algorithm F2 2 initialize set S to empty 3 for J := N - M + 1 to N do 4 T := RandInt(1, J) 5 if T is not in S then 6 insert T in S 7 else 8 insert J in S
1 //Knuth‘s Seminumerical Algorithm 2 Select := M; Remaining := N 3 for I := 1 to N do 4 if RandReal(0, 1) < Select/ Remaining then 5 print I; Select = Select - 1 6 Remaining := Remaining - 1
1 //Algorithm P 2 initialize sequence S to empty 3 for J := N - M + 1 to N do 4 T := RandInt(1, J) 5 if T is not in S then 6 prefix T to S 7 else 8 insert J in S after T
1 //Algorithm N 2 for I := 1 to N do 3 X[I] := I 4 for I := 1 to M do 5 J := RandInt(1, N) 6 Swap(X[j], X[I])
标签:
原文地址:http://www.cnblogs.com/whensean/p/a_sample_of_brilliance.html