Thema: Delphi random Problem ?

Einzelnen Beitrag anzeigen

Benutzerbild von glkgereon
glkgereon

Registriert seit: 16. Mär 2004
2.287 Beiträge
 
#4

Re: random Problem ?

  Alt 28. Jun 2004, 19:25
du sachst einfach

Delphi-Quellcode:
while i<16 do
  Begin
  x:=random(4)+1;
  if (x=1) and (anzahl1<4) //wenns in gruppe 1 soll und gruppe 1 noch nit voll ist
  then Begin
       moveitem(i,x); //schiebs in gruppe 1
       i:=i+1; //erhöh den zähler
       anzahl1:=anzahl1+1;//erhöh die anzahl der items in gruppe 1
       end;
  if (x=2) and (anzahl2<4)
  then Begin
       moveitem(i,x);
       i:=i+1;
       anzahl2:=anzahl2+1;
       end;
  if (x=3) and (anzahl3<4)
  then Begin
       moveitem(i,x);
       i:=i+1;
       anzahl3:=anzahl3+1;
       end;
  if (x=4) and (anzahl4<4)
  then Begin
       moveitem(i,x);
       i:=i+1;
       anzahl4:=anzahl4+1;
       end;
   end;
is wahrscheinölich nopch ziemlich langsam....
muss optimiert werden, in 2 minuten zusammen gestückelt....

kein if-schleife, weil dann, falls die gruppe voll ist, wird der zähler erhöht, ohne das das item reinkommt....
»Unlösbare Probleme sind in der Regel schwierig...«
  Mit Zitat antworten Zitat