Solved

Shuffle  a stringlist, how to?

Posted on 2013-12-08
2
417 Views
Last Modified: 2013-12-09
Hello Guys,

is there any function in Delphi where I can shuffle a stringlist? If no, do you have one that could me send?

I Use Delphi XE4

Consider my SL with this:

sl.Add('one');
sl.Add('two');
sl.Add('three');
sl.Add('four');
sl.Add('five');
sl.Add('six');
sl.Add('seven');
sl.Add('eight');
sl.Add('nine');
sl.Add('ten');

How can I shuffle it?

Thanks
Alex
0
Comment
Question by:hidrau
2 Comments
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 500 total points
Comment Utility
Try this:

 procedure Shuffle(list : TStringList) ;
 var
   randomIndex: integer;
   cnt: integer;
 begin
   Randomize;
   for cnt := 0 to list.Count -1 do
   begin
     randomIndex := Random(-cnt + list.Count) ;
     list.Exchange(cnt, cnt + randomIndex) ;
   end;
 end;

Open in new window

0
 
LVL 1

Author Closing Comment

by:hidrau
Comment Utility
Thanks very much.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now