请大家帮忙看看这段"抽奖"代码的思路和含义,该怎么处理

请大家帮忙看看这段"抽奖"代码的思路和含义
小弟我是新手看不大明白啊,能详细说说吗?特别是它如何实现随机抽奖的,谢谢!万分感激~

  AssignFile(BaseFile,TextEdit.Text);
  Reset(BaseFile);
  BaseLen:=0;
  While not eof(BaseFile) do
  begin
  Readln(BaseFile,BaseStr);
  BaseLen:=BaseLen+1;
  end;
  CloseFile(BaseFile);


  pickno:=StrToInt(SpinEdit1.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit4.Text);
  if pickno=0 then
  begin
  ShowMessage('您设的抽奖数量为0,程序不能执行下去!');
  Exit;
  end;

  if PickNo>BaseLen then
  begin
  ShowMessage('文本文件中的资料只有'+IntToStr(BaseLen)+'行,您设置的抽奖数量却为'+IntToStr(PickNo)+'! 请重新设置。');
  Exit;
  end;

  Gauge.Progress:=0;
  for I:=1 to PickNo do
  begin
  Gauge.Progress:=50*I Div PickNo;
  j:=0;
  randomize;
  RandomBaseLen:=Random(BaseLen)+1;
  while J<I do
  begin
  if inttostr(RandomBaseLen)<>Pick[J] then
  J:=J+1
  else
  begin
  Randomize;
  RandomBaseLen:=Random(BaseLen)+1;
  J:=0
  end;
  end;
  Pick[I]:=IntToStr(RandomBaseLen);
  end;

  AssignFile(BaseFile,TextEdit.Text);
  Reset(BaseFile);AssignFile(BaseFile,TextEdit.Text);
  Reset(BaseFile);
  for J:=1 to BaseLen do
  begin
  Gauge.Progress:=50+50*J Div BaseLen;
  Readln(BaseFile,BaseStr);
  for I:=1 to PickNo do
  begin
  if IntToStr(J)=Pick[I] then
  begin
  if I<=StrToInt(SpinEdit1.Text) then
  begin
  PickStr[I]:=BaseStr;
  break;
  end;
  if (I<=StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I>StrToInt(SpinEdit1.Text)) then
  begin
  PickStr[I]:=BaseStr;
  break;
  end;
  if (I<=StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I>StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) then
  begin
  PickStr[I]:=BaseStr;
  break;
  end;
  if (I<=StrToInt(SpinEdit4.Text)+StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I>StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) then
  begin
  PickStr[I]:=BaseStr;
  break;
  end;
  end;
  end;
  end;
  CloseFile(BaseFile);

------解决方案--------------------
[color=#FF0000][/color][color=#FF0000][/color]AssignFile(BaseFile,TextEdit.Text); 
Reset(BaseFile); 
BaseLen:=0; 
While not eof(BaseFile) do 
begin 
Readln(BaseFile,BaseStr); 
BaseLen:=BaseLen+1; //看看文件有多少行
end; 
CloseFile(BaseFile); 

//取得抽奖数量,如果为0则退出,4个SpinEdit1里是什么,暂时还不知道,应该是和数量有关系的东西吧
pickno:=StrToInt(SpinEdit1.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit4.Text); 
if pickno=0 then 
begin 
ShowMessage( '您设的抽奖数量为0,程序不能执行下去! '); 
Exit; 
end; 

if PickNo >BaseLen then //设定抽奖数量必须大于行数,具体什么资料,还不知道
begin 
ShowMessage( '文本文件中的资料只有 '+IntToStr(BaseLen)+ '行,您设置的抽奖数量却为 '+IntToStr(PickNo)+ '! 请重新设置。 '); 
Exit; 
end; 

Gauge.Progress:=0;//初始化进度条的位置为0