Random -- impacted by the computer?

M

Mark

Is the code below impacted by the computer that it is executed on, or would
one expect two computers that use the same seed to generate the same
numbers? For example, I executed the code below on two different computers
and got the same set of numbers on both machines repeatedly.

Coments? Thanks in advance.

Random number = new Random( 5 );
Random number2 = new Random( 5 );
for ( int i = 0; i < 10 ; i++)
{
Console.Out.WriteLine("Random1: " + number.Next(0 , 100).ToString());
Console.Out.WriteLine("Random2: " + number2.Next(0 , 100).ToString());
}


Thanks in advance.
Mark
 
J

Jon Skeet [C# MVP]

Mark said:
Is the code below impacted by the computer that it is executed on, or would
one expect two computers that use the same seed to generate the same
numbers? For example, I executed the code below on two different computers
and got the same set of numbers on both machines repeatedly.

Coments? Thanks in advance.

Random number = new Random( 5 );
Random number2 = new Random( 5 );
for ( int i = 0; i < 10 ; i++)
{
Console.Out.WriteLine("Random1: " + number.Next(0 , 100).ToString());
Console.Out.WriteLine("Random2: " + number2.Next(0 , 100).ToString());
}

I'd expect to get the same numbers, so long as they're using the same
version of the framework. The documentation sort of hints at this, but
without specifying it clearly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top