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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:25:21+00:00 2026-06-14T07:25:21+00:00

Maybe there is a very logic explanation for this, but I just can’t seem

  • 0

Maybe there is a very logic explanation for this, but I just can’t seem to understand why the seeds 0 and 2,147,483,647 produce the same “random” sequence, using .NET’s Random Class (System).

Quick code example:

var random1 = new Random(0);
var random2 = new Random(1);
var random3 = new Random(int.MaxValue); //2,147,483,647

var buffer1 = new byte[8];
var buffer2 = new byte[8];
var buffer3 = new byte[8];

random1.NextBytes(buffer1);
random2.NextBytes(buffer2);
random3.NextBytes(buffer3);

for (int i = 0; i < 8; i++)
{
    Console.WriteLine("{0}\t\t{1}\t\t{2}", buffer1[i], buffer2[i], buffer3[i]);
}

Output:

26      70      26
12      208     12
70      134     76
111     130     111
93      64      93
117     151     115
228     228     228
216     163     216

As you can see, the first and the third sequence are the same. Can someone please explain this to me?

EDIT: Apparently, as alro pointed out, these sequences are not the same. But they are very similar.

  • 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-06-14T07:25:22+00:00Added an answer on June 14, 2026 at 7:25 am

    Well, the reason will be connected with whatever derivation function is used by the Random class to derive a pseudo-random sequence from the seed. The real answer, therefore, is mathematical (and beyond my ability).

    Indeed – I don’t believe there’s any guarantee that two different seeds will necessarily produce different sequences anyway.

    Edit Okay – I’m going to do what bitbonk has done – but explain why:

    public Random(int Seed)
    {
        int num = (Seed == -2147483648) ? 2147483647 : Math.Abs(Seed);
        int num2 = 161803398 - num;
        this.SeedArray[55] = num2;
        int num3 = 1;
        for (int i = 1; i < 55; i++)
        {
            int num4 = 21 * i % 55;
            this.SeedArray[num4] = num3;
            num3 = num2 - num3;
            if (num3 < 0)
            {
                num3 += 2147483647;
            }
            num2 = this.SeedArray[num4];
        }
        for (int j = 1; j < 5; j++)
        {
            for (int k = 1; k < 56; k++)
            {
                this.SeedArray[k] -= this.SeedArray[1 + (k + 30) % 55];
                if (this.SeedArray[k] < 0)
                {
                    this.SeedArray[k] += 2147483647;
                }
            }
        }
        this.inext = 0;
        this.inextp = 21;
        Seed = 1;
    } 
    

    We don’t actually need to go too far into the code to see why – reading the code from top to bottom these are the values that will be stored by the above code when the seed is 0 and when the seed is 2147483647:

    int num = (Seed == -2147483648) ? 2147483647 : Math.Abs(Seed);
      =>  num is 0 and 2147483647
    
    int num2 = 161803398 - num;
      => num2 is 161803398 and -1985680249
    
    this.SeedArray[55] = num2;
      => this.SeedArray is as above in both cases
    
    int num3 = 1;
    for (int i = 1; i < 55; i++)
    {
      int num4 = 21 * i % 55
      this.SeedArray[num4] = num3;
    
      => num4 is 21, SeedArray[21] is 1
    
    num3 = num2 - num3
      => num3 is 161803397 and -1985680250
    
    if(num3 < 0)
      num3 += 2147483647
    
      => num3 is 161803397 and 161803397
    

    After just the very first loop, algorithm has already converged for the two seed values.

    Edit

    As has been pointed out on the question – the sequences aren’t the same – but they are clearly very very similar – and here we can see the reason for that similarity.

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

Sidebar

Related Questions

I'm not very good at regex but maybe there's a simple way to achieve
Maybe there is a proper term for this, but what if you want to
Maybe there's no way to solve this the way I'd like it but I
I call this a flash meeting, but maybe there is another more appropriate name.
Maybe there is no difference, but is either way better than the other (or
I haven't exactly found the answer to this, maybe there is no best one.
Sorry for the very involved question, but this is something I've been researching for
All, This question probably has a very simple answer - something I'm overlooking. But
Just a very general question, that not only applies to this example. Let's say
I'm very new to jQuery and javascript in general, so maybe there's something I've

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.