Link to home
Start Free TrialLog in
Avatar of brettawv
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.
Avatar of men xin
men xin
Flag of China image

like winamp,initiate the list at the first time(use a array and random)
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
ASKER CERTIFIED SOLUTION
Avatar of edey
edey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fatman121898
Fatman121898

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.
You should only call Randomize ONCE.
Did I call it more than once? ;-)

Jo.