Randomize StringList

后端 未结 3 1438
有刺的猬
有刺的猬 2020-12-06 10:41

How can I randomize the Strings in the StringList similarly how this online tool works. If anyone is familiar with it, check this: http://textmechanic.co/Randomize-List.html

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 11:24

    Just loop through the stringlist and give each item an different random place:

    for i := StringList.Count - 1 downto 1 do
      StringList.Exchange(i, Random(i+1));
    

    [edit] Altered the loop a bit to make the shuffling uniform.

提交回复
热议问题