Gracias ecfisa y bucanero, miraré vuestro codigo sin falta por que ya no sé que mas hacer (lmitación de conocimientos siendo honesto)
En este momento, tengo este codigo para generar los aleatorios no repeditos
en una unidad aparte, uso esta funcion para generar los aleatorios no repetidos:
Código Delphi
[-]unit RandomArray;
{$MODE Delphi}
interface
uses LCLIntf, LCLType, LMessages;
type
TIntegerArray = array[0..32760*2] of Integer;
PIntegerArray = ^TIntegerArray;
function CompRandArray(var IntArrayPtr: PIntegerArray; Count, LowRange, HighRange: integer): boolean;
implementation
function CompRandArray(var IntArrayPtr: PIntegerArray; Count, LowRange, HighRange: integer): boolean;
var
I, J: integer;
HaveDup: boolean;
begin
Result := True;
if (HighRange - LowRange + 1) < (Count) then
begin
Result := False;
Exit;
end;
Randomize;
for I := 0 to Count - 1 do
begin
IntArrayPtr^[i] := LowRange + Random(HighRange - LowRange + 1);
Repeat
HaveDup := False;
for J := 0 to I - 1 do
begin
if (IntArrayPtr^[J] = IntArrayPtr^[i]) and (I <> J) then
begin
IntArrayPtr^[i] := LowRange + Random(HighRange - LowRange + 1);
HaveDup := True;
break;
end;
end;
Until HaveDup = False;
end;
end;
end.
en la unidad principal tengo esto...
Código Delphi
[-]unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ComCtrls, Grids, RandomArray;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
grid: TStringGrid;
Label1: TLabel;
lista: TListView;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.Button1Click(Sender: TObject);
var
RandomArray: PIntegerArray; i, Ctr, Count, Low, High: integer;
begin
Count := 6; Low := 1; High := 49; GetMem(RandomArray, Count*SizeOf(Integer)); try
ListBox1.Clear;
if CompRandArray(RandomArray, Count, Low, High) then
For Ctr := 0 to Count - 1 do
ListBox1.Items.Add(IntToStr(RandomArray^[Ctr])); finally
FreeMem(RandomArray, Count*SizeOf(Integer)); end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i,j: integer;
begin
with Lista.Items.Add do
begin
for i:= 0 to listBox1.Items.Count -1 do
SubItems.Add(listBox1.Items.Strings[i]);
end;
button1.Click;
end;
end.
Bien, cada vez que pulso el button1, se genera en el listbox1 una combinacion de 6 numeros aleatorios sin repeticion y si pulso el button2, mete el contenido del listbox1 en el listview y hace una llamada a button1.
Y aqui viene mi problema por mucho que coloco for y while... no consigo rellenar el listview con por ejemplo 50, 100, 140 combinaciones de 6 numeros aleatorios que me entrege la funcion, o mejor dicho, lo rellena pero salvo la primera fila, el resto siempre son la misma combinacion.
Ejemplo:
3 5 7 12 45 32
23 4 12 41 33 13
23 4 12 41 33 13
23 4 12 41 33 13
23 4 12 41 33 13
...
Saludos y
muchas gracias por vuestro tiempo, ayuda y paciencia.