Autor Beitrag
minipliman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: So 15.01.06 20:40 
ich hab n arry mit 6 zahlen und die sollen jetzt zufällig gemischt werden wie mach ich das?
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 15.01.06 20:47 
Welche Ansätze hast du bis jetzt? Hast du schon irgendwelchen Code?

AXMD
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: So 15.01.06 21:08 
sowat ?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button2Click(Sender: TObject);
procedure exchange(var a,b:integer);
var c: integer;
begin
  c:=a;
  a:=b;
  b:=c;
end;
var ma: array[1..6] of integer;
    i:integer;
begin
   for i := 1 to 6 do ma[i] := i;
   for i := 1 to 36 do exchange(ma[random(6)+1],ma[random(6)+1]);
   for i := 1 to 6 do memo1.Lines.add(inttostr(ma[i]));
end;
k-weddige
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 49

Win Vista Business
C# (VS 2008 Professional)
BeitragVerfasst: Mo 16.01.06 16:52 
Viel Zufall machts auch nicht zufälliger!
Besser ist's IMHO so:
ausblenden Delphi-Quelltext
1:
for i:=1 to 6 do exchange(ma[i],ma[random(6)+1]					

So wird mit minimalem Aufwand sichergestellt, dass jedes Element mindestens einmal vertauscht wird.
Zufälliger gehts (mit random) nicht.

Konstantin

_________________
Meine Programme sind perfekt, der Computer versteht sie bloß nicht.