Solved

Shuffle  a stringlist, how to?

Posted on 2013-12-08
2
445 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can Viruses spread while transferring Binary data with Winsock 2 105
Magic Software info 18 152
Convert MS Word document to a PDF file 9 133
Delphi Seattle StructureView color 1 33
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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