Here's the code I'm trying to synchronize. Both computers use this exact
method.
RandomNumberSeed is an integer property
///
public int RandomNumberSeed
{
get { return randomNumberSeed; }
set { randomNumberSeed = value;}
}
BreakUpRandomSeeds is a method I use for generating new random seeds later
on.
Notice I'm printing out the results as soon as they are generated. The
property is merely a placeholder for the data.
///
private void BreakUpRandomSeeds(Unit unit, int seed)
{
Random rnd = new Random(seed);
unit.a.RandomNumberSeed = rnd.Next();
unit.b.RandomNumberSeed = rnd.Next();
unit.c.RandomNumberSeed = rnd.Next();
LogFile.Log("BreakUp: " +
unit.Delta.Name + ": " +
seed + " " +
unit.a.RandomNumberSeed + " " +
unit.b.RandomNumberSeed + " " +
unit.c.RandomNumberSeed);
}
For now, I changed the code a bit. Instead of grabbing .Next(), I use
..Next(1000), which may be just random enough.
So far, I haven't seen differences on both machines. I'm worried that
whatever was causing the slight error I was seeing for the larger
numbers may once in a while cause a rounding difference with the 0 to 1000
set. So far, this hasn't been the case.
I wish I knew more about the internals of the Random class.
"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Can you post the code you are using that generates the output you showed?
(For both machine 1 and machine 2)
--
Adam Clauss
ca*****@tamu.edu
"Marshall Belew" <mb****@koiosworks.com> wrote in message
news:10*************@corp.supernews.com...
Oddity: I can't really reproduce this when I use a stand alone
application. It seems to only happen in my primary app.
"Marshall Belew" <mb****@koiosworks.com> wrote in message
news:10*************@corp.supernews.com... Yes, mscorlib.dll version 1.1.4322.573.
"Julie" <ju***@nospam.com> wrote in message
news:41***************@nospam.com...
> Marshall Belew wrote:
> >
> > I'm trying to synchronize a network app that uses random numbers
> > generated by System.Random. Rather than pass every randomly
generated > > number, I just pass the seed. I'm seeing a result that leads me to
> > believe that a seeded random number is still slightly random. I
need > > a predictable random number.
> >
> > Here's my results
> >
> > Machine 1
> > Seed: 1453549276
> >
> > random.Next() = 1997009408
> > random.Next() = 2105130240
> > random.Next() = 557073472
> >
> > Machine 2
> > Seed: 1453549276
> >
> > random.Next() = 1997009351
> > random.Next() = 2105130259
> > random.Next() = 557073440
> >
> > You can see that the last few digits of the random numbers are
> > slightly off. Anyone have any suggestions on how I can generate
> > predictable random numbers in C#?
> >
> > Thanks!
> >
> > Marshall Belew
>
> Does each machine have the same version of the .Net framework
installed?