Solved

Shuffle  a stringlist, how to?

Posted on 2013-12-08
2
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 39704614
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
ID: 39706617
Thanks very much.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 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