anchor.diff:      Shuffled = etorrent_utils:shuffle(Remaining),
       {endgame, lists:sublist(Shuffled, N)}.
   
  -%% @doc Choose up to Max chunks from Selected.
  -%%  Will return {ok, {Index, Chunks}, size(Chunks)}.
  -%% @end
  --spec select_chunks_by_piecenum([#chunk{}], pos_integer(), pid()) ->
  -			   {ok, {pos_integer(), term()}, non_neg_integer()}.
  -select_chunks_by_piecenum(Selected, Max, Pid) ->
  -    %% Get up to Max chunks
  -    {Return, _Rest} = etorrent_utils:gsplit(Max, Selected),
  -    [H|_] = Return,
  -    {Id, Index, _} = H#chunk.idt,
  -    %% Assign chunk to us
  -    Chunks = [begin
  -		  ets:delete_object(?TAB, C),
  -		  ets:insert(?TAB,
  -			     [C#chunk {
  -				idt = {Id, Index, {assigned, Pid}} }]),
  -		  C#chunk.chunk
  -	      end || C <- Return],
  -    {ok, {Index, Chunks}, length(Chunks)}.
   
   -spec pick_chunks_endgame(integer(), gb_set(), integer(), X) -> X | {endgame, [#chunk{}]}.
   pick_chunks_endgame(Id, Set, Remaining, Ret) ->
  
positive.code: 		 {reply, found, S}
      end;
  %% @todo: If we have an idt with {assigned, pid()}, do we have chunk = Offset?
  handle_call({endgame_remove_chunk, SendPid, Id, {Index, Offset, _Len}},
              _From, S) ->
      ets:match_delete(?TAB,
  		      #chunk { idt = {Id, Index, {assigned, SendPid}},
  			       chunk = Offset }),
      {reply, ok, S};
  handle_call({pick_chunks, Id, Set, Remaining}, {Pid, _Tag}, S) ->
      R = case pick_chunks(pick_chunked, {Pid, Id, Set, [], Remaining, none}) of
              not_interested -> pick_chunks_endgame(Id, Set, Remaining, not_interested);
              {ok, []}       -> pick_chunks_endgame(Id, Set, Remaining, none_eligible);
              {ok, Items}    -> {ok, Items}
          end,
      {reply, R, S};
  handle_call(_Request, _From, State) ->
      Reply = ok,
      {reply, Reply, State}.
  
negative.code: pick_chunks(_Id, unknown, _N) ->
      none_eligible;
  pick_chunks(Id, Set, N) ->
      case pick_chunks(pick_chunked, {self(), Id, Set, [], N, none}) of
  	not_interested -> pick_chunks_endgame(Id, Set, N, not_interested);
  	{ok, []}       -> pick_chunks_endgame(Id, Set, N, none_eligible);
  	{ok, Items}    -> {ok, Items}
      end.
  
  % @doc Request the managing of a new torrent identified by Id
  % <p>Note that the calling Pid is tracked as being the owner of the torrent.
  