Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > Lazarus, FreePascal, Kylix, etc.
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #9  
Antiguo 09-05-2018
Avatar de danielmj
danielmj danielmj is offline
Miembro
 
Registrado: jun 2011
Posts: 383
Poder: 13
danielmj Va por buen camino
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; //fuente: https://www.experts-exchange.com/que...f-numbers.html

{$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 }

  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}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  RandomArray: PIntegerArray; //This is a pointer type to Dynamic array
  i, Ctr, Count, Low, High: integer;

  begin
    Count := 6; //fill with 20 items
    Low := 1; //Lowest Random Number
    High := 49; //Highest Random Number
    GetMem(RandomArray, Count*SizeOf(Integer)); //Allocate memory
    try
      ListBox1.Clear;
      if CompRandArray(RandomArray, Count, Low, High) then
        For Ctr := 0 to Count - 1 do
        //if false Something went wrong
        ListBox1.Items.Add(IntToStr(RandomArray^[Ctr])); //dont forget ^
    finally
      FreeMem(RandomArray, Count*SizeOf(Integer)); //DeAllocate
    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.
__________________
La juventud pasa, la inmadurez se supera, la ignorancia se cura con la educación, y la embriaguez con la sobriedad, pero la estupidez dura para siempre. Aristofanes.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
sumando valores de un listview danielmj Varios 28 14-11-2014 21:52:30
VALORES FANTASMAS FIREBIRD 2.1 valores Grandes ASAPLTDA Firebird e Interbase 17 02-12-2012 12:09:02
Rellenar con 0.... buitrago Varios 6 17-11-2011 20:02:53
¿Cómo insertar una imágen en un lisbox o un memo? Acuarius3000 Gráficos 3 27-06-2005 08:44:53
arastrar archivos a un lisbox gulder C++ Builder 3 05-05-2005 13:31:50


La franja horaria es GMT +2. Ahora son las 00:47:26.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi