brettawv
asked on
Shuffle Lines In A Memo
I am writing an application to play Mp3 Files. I am using the memo for my play list. I want to shuffle the songs in the memo but I don't want to use random, because I don't want the same song to play twice. Does anyone have some advice on how to do this.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In order to avoid the same playlist order every time you start it, you should use Randomize procedure before using Random function. The code proposed by edey should be modified in this way:
procedure swap(var t : TStringList);
var
ix,src,dst : integer;
s : string;
begin
Randomize;
for ix := 0 to 100 do
begin
src := random(t.count);
dst := random(t.count);
s := t[dst];
t[dst] := t[src];
t[src] := s;
end;
end;
Jo.
procedure swap(var t : TStringList);
var
ix,src,dst : integer;
s : string;
begin
Randomize;
for ix := 0 to 100 do
begin
src := random(t.count);
dst := random(t.count);
s := t[dst];
t[dst] := t[src];
t[src] := s;
end;
end;
Jo.
You should only call Randomize ONCE.
Did I call it more than once? ;-)
Jo.
Jo.
Like this.
public var i:integer=0;
oncreate:
shuffle();
after a song completed:
if i=songscount then begin
i:=0;
shuffle();
end else
inc(i);
shuffle function:
random...
Sorry for my POOR English.
menxin