Tema: RandomRange
Ver Mensaje Individual
  #7  
Antiguo 02-10-2006
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.142
Reputación: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Ten en cuenta lo que dice la ayuda sobre el procedimiento "Randomize", entre otras cosas:

Cita:
Empezado por Ayuda de Delphi
Do not combine the call to Randomize in a loop with calls to the Random function. Typically, Randomize is called only once, before all calls to Random.
Es decir, más bien que esto:

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  numeroAleatorioDelUnoAlCien: Integer;
begin
  for i := 1 to 100 do
  begin
    Randomize;
    numeroAleatorioDelUnoAlCien := Math.RandomRange(1, 100);
    Caption := IntToStr(numeroAleatorioDelUnoAlCien);
  end;
end;

... mejor hacer esto otro, o sea, quitar el "Randomize" del bucle:

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  numeroAleatorioDelUnoAlCien: Integer;
begin
  Randomize;
  for i := 1 to 100 do
  begin
    numeroAleatorioDelUnoAlCien := Math.RandomRange(1, 100);
    Caption := IntToStr(numeroAleatorioDelUnoAlCien);
  end;
end;
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita