Click here to Skip to main content
15,034,432 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
How to shuffle the lines in a text file?
Posted
Updated 3-Nov-10 10:12am
v3
Comments
fjdiewornncalwe 3-Nov-10 9:55am
   
You need to be a little more specific than this.
Abhinav S 3-Nov-10 9:58am
   
Little more information required.
Rajesh Anuhya 3-Nov-10 10:00am
   
More Clarification required on your Question

You may read the lines into an array of strings and then shuffle the array indices (and finally write back the array into a file).
:)
   
v2
Here's some LINQ code that shows how to do this as CPallini suggested:

C#
Random random = new Random();
File.WriteAllLines(fileName, File.ReadAllLines(fileName).OrderBy(s => random.Next()).ToArray());
   
Comments
CPallini 3-Nov-10 10:31am
   
Wow, that's wonderfully terse.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900