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 7536907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:42:12+00:00 2026-05-30T06:42:12+00:00

I have got an IEnumerable collection as follows var result1 = GetResult1() // Returns

  • 0

I have got an IEnumerable collection as follows

var result1 = GetResult1() // Returns 2,4,5,6

I have to juggle the elements and create another collection in a random way which should result as follows:

var result2 = GetResult2(result1) // Returns 2,4,5,6 in a random order.
// An example output would be 4,6,2,5 in the resultant collection.

I have done this by the following means:

var result1 = GetResult1();
var random = new Random();
var result2 = result1.OrderBy(order=>random.Next());

However the issue with this is that if I access result2 the elements in result2 gets shuffled again, i.e if I output the results of result2 to a console twice, the elements are juggled again.

Can you please advice how to keep this uniform. i.e once I juggle the collection, it should remain the same way thereafter. I have to use lazy evaluation though, since the results are very huge in size.

  • 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-30T06:42:14+00:00Added an answer on May 30, 2026 at 6:42 am

    I see you require lazy evaluation for the results, if that is the case, what you can do is this:

    var randomNumbers = result1.Select(r => random.Next()).ToArray();
    var orderedResult = result1.Zip(randomNumbers, (r, o) => new { Result = r, Order = o })
        .OrderBy(o => o.Order)
        .Select(o => o.Result);
    

    By calling ToArray() on the random numbers, these will not change. When you finally desire the items in result1, you can zip the items with the random numbers, OrderBy the random number and Select the result.

    As long as the items in result1 come in the same order, the result in orderedResult should be the same each time.

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

Sidebar

Related Questions

I have an IEnumerable<MyObject> collection, with N MyObject elements. MyObject is a class with
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I've got a Customer object with a Collection of CustomerContacts IEnumerable<CustomerContact> Contacts { get;
I got a model defined as IEnumerable<MyViewModel> which I tried to use to create
when using a MVC 3 collection that uses IEnumerable, is there a way to
I've got another question with List of lists. Once again, I have the generic
Simple example - you have a method or a property that returns an IEnumerable
I have got a question about the order in IEnumerable . As far as
Have got an NSString *str = @12345.6789 and want to find out if there
I have got the requirement to find the core file in multiple box/machine and

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.