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.
brettawvAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

men xinCEOCommented:
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
0
edeyCommented:
I think what menxin is alluding to is to create a randomized list by modifying the original.  For example, "swap" two lines in you TStringList, & repeat a large number of times like so:

procedure swap(t : TStringList);
var
 ix,src,dst : integer;
 s : string;
begin
 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;


One should note that the above is untested (and could prob. be considered pseudo code :)


GL
Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fatman121898Commented:
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.
0
DragonSlayerCommented:
You should only call Randomize ONCE.
0
Fatman121898Commented:
Did I call it more than once? ;-)

Jo.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.