Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:31:09+00:00 2026-05-31T09:31:09+00:00

I want to shuffle two lists, such that they are shuffled in the same

  • 0

I want to shuffle two lists, such that they are shuffled in the same way (provided that I have a method Shuffle(List list) that shuffles one list.

List<ObjX> listA = new List<ObjX>() { A, B, C, D };
List<ObjX> listB = new List<ObjX>() { W, X, Y, Z };
ShuffleTwoLists(listA , listB )

Result:
A: C, B, D, A
B: Y, X, Z, W

Is there a quick way to implement ShuffleTwoLists(listA , listB) in C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:31:11+00:00Added an answer on May 31, 2026 at 9:31 am

    Option 1: zip, shuffle, unzip

    To expand on Marcelo’s comment, and assuming you don’t mind creating new lists instead of shuffling the existing ones:

    var zipped = listA.Zip(listB, (a, b) => new { a, b } ).ToList();
    Shuffle(zipped);
    var newListA = zipped.Select(pair => pair.a).ToList();
    var newListB = zipped.Select(pair => pair.b).ToList();
    

    Option 2: shuffle the indexes

    To expand on MAK’s answer with code:

    var indexes = Enumerable.Range(0, listA.Count).ToList();
    Shuffle(indexes);
    var newListA = indexes.Select(index => listA[index]).ToList();
    var newListB = indexes.Select(index => listB[index]).ToList();
    

    Of course both approaches could mutate the original lists, with a bit more work.

    Option 3: shuffle both lists with the same random seed

    I personally like to pass a Random (or whatever) into methods/classes which need them instead of creating new ones. So I’d give my Shuffle a Random parameter. It avoids various problems, and expresses the dependency nicely. You can use this to your advantage, by creating two Random instances with the same seed:

    int seed = existingRandom.Next();
    Shuffle(listA, new Random(seed));
    Shuffle(listB, new Random(seed));
    

    Assuming Shuffle does the same thing when given the same sequence of random numbers, this will shuffle both lists in the same way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's that time of year again that programmers want to shuffle a list such
I want to create a shuffled set of integers such that: Given the same
i have this function that will shuffle a list of images, when i press
I have two NSMutableArrays of strings that I wish to combine and shuffle together.
I have 'n' button. I want to shuffle those button in my application. Or
i want after i shuffle a list of images to get all the alt=
I have a set of 4 strings and want to generate a list of
I have two numpy arrays of different shapes, but with the same length (leading
I have a Delphi application similar to Taskbar Shuffle that includes a hook dll.
I have two arrays with a series of integers. I want to simulate cutting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.