By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

Problem with Random()

P: n/a
If I use it in my page it's fine but when I put it in a Class file for
calling it returns the same # for each call.
Any ideas why? I'm sure it's something I'll slap myself for but the only
samples I can find are for calling the Random() within the page, not a
seperate class.

--Page--
myClass myclass = new myClass();
for(int i = 1;i <= 100; i++)
{
this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
}

---- class file
public string GetRandom()
{
Random rnd = new Random();
return rnd.Next(1,100));
}

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com

Nov 18 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
The random number generation starts from a seed value. If the same seed is
used repeatedly, the same series of numbers is generated. One way to produce
different sequences is to make the seed value time-dependent, thereby
producing a different series with each new instance of Random.

To improve performance, create one Random to generate many random numbers
over time, instead of repeatedly creating a new Random to generate one
random number.

extract from msdn. Time Dependant seed.
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
If I use it in my page it's fine but when I put it in a Class file for
calling it returns the same # for each call.
Any ideas why? I'm sure it's something I'll slap myself for but the only
samples I can find are for calling the Random() within the page, not a
seperate class.

--Page--
myClass myclass = new myClass();
for(int i = 1;i <= 100; i++)
{
this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
}

---- class file
public string GetRandom()
{
Random rnd = new Random();
return rnd.Next(1,100));
}

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com

Nov 18 '05 #2

P: n/a
I had tried with the seed being System.DateTime.Now.Millisecond but my
numbers must generate too fast for that to work. Must need nanosecond I
guess........

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP15.phx.gbl...
The random number generation starts from a seed value. If the same seed is
used repeatedly, the same series of numbers is generated. One way to
produce
different sequences is to make the seed value time-dependent, thereby
producing a different series with each new instance of Random.

To improve performance, create one Random to generate many random numbers
over time, instead of repeatedly creating a new Random to generate one
random number.

extract from msdn. Time Dependant seed.
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
If I use it in my page it's fine but when I put it in a Class file for
calling it returns the same # for each call.
Any ideas why? I'm sure it's something I'll slap myself for but the only
samples I can find are for calling the Random() within the page, not a
seperate class.

--Page--
myClass myclass = new myClass();
for(int i = 1;i <= 100; i++)
{
this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
}

---- class file
public string GetRandom()
{
Random rnd = new Random();
return rnd.Next(1,100));
}

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


Nov 18 '05 #3

P: n/a
i know it still doesnt explain
If I use it in my page it's fine but when I put it in a Class >file for calling it returns the same # for each call.

I did look around if i find anything i will drop in a message

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP15.phx.gbl... The random number generation starts from a seed value. If the same seed is
used repeatedly, the same series of numbers is generated. One way to produce different sequences is to make the seed value time-dependent, thereby
producing a different series with each new instance of Random.

To improve performance, create one Random to generate many random numbers
over time, instead of repeatedly creating a new Random to generate one
random number.

extract from msdn. Time Dependant seed.
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
If I use it in my page it's fine but when I put it in a Class file for
calling it returns the same # for each call.
Any ideas why? I'm sure it's something I'll slap myself for but the only
samples I can find are for calling the Random() within the page, not a
seperate class.

--Page--
myClass myclass = new myClass();
for(int i = 1;i <= 100; i++)
{
this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
}

---- class file
public string GetRandom()
{
Random rnd = new Random();
return rnd.Next(1,100));
}

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


Nov 18 '05 #4

P: n/a
another lame attempt at trying to read between lines

Represents a pseudo-random number generator, a device that produces a
sequence of numbers that meet certain statistical requirements for
randomness.

this is more of a 'Can you do it this way'

how about making your Random class wrapper as Static
and making the last ramdom as static variable which is used as a seed for
the next() method !!

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eC**************@TK2MSFTNGP15.phx.gbl...
I had tried with the seed being System.DateTime.Now.Millisecond but my
numbers must generate too fast for that to work. Must need nanosecond I
guess........

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP15.phx.gbl...
The random number generation starts from a seed value. If the same seed is used repeatedly, the same series of numbers is generated. One way to
produce
different sequences is to make the seed value time-dependent, thereby
producing a different series with each new instance of Random.

To improve performance, create one Random to generate many random numbers over time, instead of repeatedly creating a new Random to generate one
random number.

extract from msdn. Time Dependant seed.
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
If I use it in my page it's fine but when I put it in a Class file for
calling it returns the same # for each call.
Any ideas why? I'm sure it's something I'll slap myself for but the only samples I can find are for calling the Random() within the page, not a
seperate class.

--Page--
myClass myclass = new myClass();
for(int i = 1;i <= 100; i++)
{
this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
}

---- class file
public string GetRandom()
{
Random rnd = new Random();
return rnd.Next(1,100));
}

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com



Nov 18 '05 #5

P: n/a
have a look at http://hdave.myvnc.com/WebApplication1/WebForm1.aspx

public class MyClass
{
Random rdm1;
Random rdm2;
int seed = 1;
int Max = 100;
public MyClass()
{
//
// TODO: Add constructor logic here
//
rdm1 = new Random();
rdm2 = new Random(seed);
}
public int GetRandon11()
{
return rdm1.Next(seed, Max);
}
public int GetRandom21()
{
return rdm1.Next(seed, Max);
}
}

it's sort of working fine. need some dinner now.. brb

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
If I use it in my page it's fine but when I put it in a Class file for
calling it returns the same # for each call.
Any ideas why? I'm sure it's something I'll slap myself for but the only
samples I can find are for calling the Random() within the page, not a
seperate class.

--Page--
myClass myclass = new myClass();
for(int i = 1;i <= 100; i++)
{
this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
}

---- class file
public string GetRandom()
{
Random rnd = new Random();
return rnd.Next(1,100));
}

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com

Nov 18 '05 #6

P: n/a
Curt,

Out of interest, try using the tickcount as the seed

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eC**************@TK2MSFTNGP15.phx.gbl...
I had tried with the seed being System.DateTime.Now.Millisecond but my
numbers must generate too fast for that to work. Must need nanosecond I
guess........

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP15.phx.gbl...
The random number generation starts from a seed value. If the same seed is used repeatedly, the same series of numbers is generated. One way to
produce
different sequences is to make the seed value time-dependent, thereby
producing a different series with each new instance of Random.

To improve performance, create one Random to generate many random numbers over time, instead of repeatedly creating a new Random to generate one
random number.

extract from msdn. Time Dependant seed.
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
If I use it in my page it's fine but when I put it in a Class file for
calling it returns the same # for each call.
Any ideas why? I'm sure it's something I'll slap myself for but the only samples I can find are for calling the Random() within the page, not a
seperate class.

--Page--
myClass myclass = new myClass();
for(int i = 1;i <= 100; i++)
{
this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
}

---- class file
public string GetRandom()
{
Random rnd = new Random();
return rnd.Next(1,100));
}

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com



Nov 18 '05 #7

P: n/a
i think the sole reason it think he had the problem was that he was creating
an instance with every call and i think as msdn states it products pseudo
randomness as long as you use the same object.

i have tried it with using the same object rather than creating and
disposing instance per call and it works just fine

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
Curt,

Out of interest, try using the tickcount as the seed

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eC**************@TK2MSFTNGP15.phx.gbl...
I had tried with the seed being System.DateTime.Now.Millisecond but my
numbers must generate too fast for that to work. Must need nanosecond I
guess........

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP15.phx.gbl...
The random number generation starts from a seed value. If the same seed
is used repeatedly, the same series of numbers is generated. One way to
produce
different sequences is to make the seed value time-dependent, thereby
producing a different series with each new instance of Random.

To improve performance, create one Random to generate many random numbers over time, instead of repeatedly creating a new Random to generate one
random number.

extract from msdn. Time Dependant seed.
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:e0**************@TK2MSFTNGP11.phx.gbl...
> If I use it in my page it's fine but when I put it in a Class file
for> calling it returns the same # for each call.
> Any ideas why? I'm sure it's something I'll slap myself for but the

only> samples I can find are for calling the Random() within the page, not a> seperate class.
>
> --Page--
> myClass myclass = new myClass();
> for(int i = 1;i <= 100; i++)
> {
> this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
> }
>
> ---- class file
> public string GetRandom()
> {
> Random rnd = new Random();
> return rnd.Next(1,100));
> }
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> Site: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
>
>



Nov 18 '05 #8

P: n/a
Actually I had tried it both ways. The execution was to fast for the seed to
the the tickcount or now.millisecond so what I did was in each iteration I
increased the ((seed + 1) * pi) to get a new number. Using seed++ ended up
giving me an easily distinguishable pattern.

Thanks for the help all. That darn seed thing is just goofy, and not
documented well.
I read it and thought it was the time/duration that the current iteration
would maintian uniqueness, guess you learn.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:O5****************@TK2MSFTNGP09.phx.gbl...
i think the sole reason it think he had the problem was that he was
creating
an instance with every call and i think as msdn states it products pseudo
randomness as long as you use the same object.

i have tried it with using the same object rather than creating and
disposing instance per call and it works just fine

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
Curt,

Out of interest, try using the tickcount as the seed

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eC**************@TK2MSFTNGP15.phx.gbl...
> I had tried with the seed being System.DateTime.Now.Millisecond but my
> numbers must generate too fast for that to work. Must need nanosecond I
> guess........
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> Site: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
>
> "Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message > news:uv**************@TK2MSFTNGP15.phx.gbl...
> > The random number generation starts from a seed value. If the same seed
is
> > used repeatedly, the same series of numbers is generated. One way to
> > produce
> > different sequences is to make the seed value time-dependent, thereby
> > producing a different series with each new instance of Random.
> >
> > To improve performance, create one Random to generate many random

numbers
> > over time, instead of repeatedly creating a new Random to generate
> > one
> > random number.
> >
> > extract from msdn. Time Dependant seed.
> >
> >
> > --
> >
> > Regards,
> >
> > Hermit Dave
> > (http://hdave.blogspot.com)
> > "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
> > news:e0**************@TK2MSFTNGP11.phx.gbl...
> >> If I use it in my page it's fine but when I put it in a Class file

for > >> calling it returns the same # for each call.
> >> Any ideas why? I'm sure it's something I'll slap myself for but the

only
> >> samples I can find are for calling the Random() within the page, not a > >> seperate class.
> >>
> >> --Page--
> >> myClass myclass = new myClass();
> >> for(int i = 1;i <= 100; i++)
> >> {
> >> this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
> >> }
> >>
> >> ---- class file
> >> public string GetRandom()
> >> {
> >> Random rnd = new Random();
> >> return rnd.Next(1,100));
> >> }
> >>
> >> --
> >> Curt Christianson
> >> Owner/Lead Developer, DF-Software
> >> Site: http://www.Darkfalz.com
> >> Blog: http://blog.Darkfalz.com
> >>
> >>
> >>
> >
> >
>
>



Nov 18 '05 #9

P: n/a
I'm suprised that the execution was too fast for tickcount, I thought that
was impossible. Glad you have a solution anyway and I agree that seeding is
darn goofy.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
Actually I had tried it both ways. The execution was to fast for the seed to the the tickcount or now.millisecond so what I did was in each iteration I
increased the ((seed + 1) * pi) to get a new number. Using seed++ ended up
giving me an easily distinguishable pattern.

Thanks for the help all. That darn seed thing is just goofy, and not
documented well.
I read it and thought it was the time/duration that the current iteration
would maintian uniqueness, guess you learn.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:O5****************@TK2MSFTNGP09.phx.gbl...
i think the sole reason it think he had the problem was that he was
creating
an instance with every call and i think as msdn states it products pseudo randomness as long as you use the same object.

i have tried it with using the same object rather than creating and
disposing instance per call and it works just fine

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
Curt,

Out of interest, try using the tickcount as the seed

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:eC**************@TK2MSFTNGP15.phx.gbl...
> I had tried with the seed being System.DateTime.Now.Millisecond but my > numbers must generate too fast for that to work. Must need nanosecond I > guess........
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> Site: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
>
> "Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in

message
> news:uv**************@TK2MSFTNGP15.phx.gbl...
> > The random number generation starts from a seed value. If the same

seed
is
> > used repeatedly, the same series of numbers is generated. One way to > > produce
> > different sequences is to make the seed value time-dependent, thereby > > producing a different series with each new instance of Random.
> >
> > To improve performance, create one Random to generate many random
numbers
> > over time, instead of repeatedly creating a new Random to generate
> > one
> > random number.
> >
> > extract from msdn. Time Dependant seed.
> >
> >
> > --
> >
> > Regards,
> >
> > Hermit Dave
> > (http://hdave.blogspot.com)
> > "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
> > news:e0**************@TK2MSFTNGP11.phx.gbl...
> >> If I use it in my page it's fine but when I put it in a Class file

for
> >> calling it returns the same # for each call.
> >> Any ideas why? I'm sure it's something I'll slap myself for but the only
> >> samples I can find are for calling the Random() within the page,
not a
> >> seperate class.
> >>
> >> --Page--
> >> myClass myclass = new myClass();
> >> for(int i = 1;i <= 100; i++)
> >> {
> >> this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
> >> }
> >>
> >> ---- class file
> >> public string GetRandom()
> >> {
> >> Random rnd = new Random();
> >> return rnd.Next(1,100));
> >> }
> >>
> >> --
> >> Curt Christianson
> >> Owner/Lead Developer, DF-Software
> >> Site: http://www.Darkfalz.com
> >> Blog: http://blog.Darkfalz.com
> >>
> >>
> >>
> >
> >
>
>



Nov 18 '05 #10

P: n/a
yeah, somehow it was.
I was runing it 10 times and would get 6,8, sometimes 10 of them the same.
Guess the machines have taken over.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
news:eS****************@tk2msftngp13.phx.gbl...
I'm suprised that the execution was too fast for tickcount, I thought that
was impossible. Glad you have a solution anyway and I agree that seeding
is
darn goofy.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
Actually I had tried it both ways. The execution was to fast for the seed

to
the the tickcount or now.millisecond so what I did was in each iteration
I
increased the ((seed + 1) * pi) to get a new number. Using seed++ ended
up
giving me an easily distinguishable pattern.

Thanks for the help all. That darn seed thing is just goofy, and not
documented well.
I read it and thought it was the time/duration that the current iteration
would maintian uniqueness, guess you learn.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:O5****************@TK2MSFTNGP09.phx.gbl...
>i think the sole reason it think he had the problem was that he was
>creating
> an instance with every call and i think as msdn states it products pseudo > randomness as long as you use the same object.
>
> i have tried it with using the same object rather than creating and
> disposing instance per call and it works just fine
>
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "John Timney (Microsoft MVP)" <ti*****@despammed.com> wrote in message
> news:e5**************@TK2MSFTNGP09.phx.gbl...
>> Curt,
>>
>> Out of interest, try using the tickcount as the seed
>>
>> --
>> Regards
>>
>> John Timney
>> Microsoft Regional Director
>> Microsoft MVP
>>
>>
>> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
>> news:eC**************@TK2MSFTNGP15.phx.gbl...
>> > I had tried with the seed being System.DateTime.Now.Millisecond but my >> > numbers must generate too fast for that to work. Must need
>> > nanosecond I >> > guess........
>> >
>> > --
>> > Curt Christianson
>> > Owner/Lead Developer, DF-Software
>> > Site: http://www.Darkfalz.com
>> > Blog: http://blog.Darkfalz.com
>> >
>> >
>> > "Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in
> message
>> > news:uv**************@TK2MSFTNGP15.phx.gbl...
>> > > The random number generation starts from a seed value. If the same
> seed
>> is
>> > > used repeatedly, the same series of numbers is generated. One way to >> > > produce
>> > > different sequences is to make the seed value time-dependent, thereby >> > > producing a different series with each new instance of Random.
>> > >
>> > > To improve performance, create one Random to generate many random
>> numbers
>> > > over time, instead of repeatedly creating a new Random to generate
>> > > one
>> > > random number.
>> > >
>> > > extract from msdn. Time Dependant seed.
>> > >
>> > >
>> > > --
>> > >
>> > > Regards,
>> > >
>> > > Hermit Dave
>> > > (http://hdave.blogspot.com)
>> > > "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
>> > > news:e0**************@TK2MSFTNGP11.phx.gbl...
>> > >> If I use it in my page it's fine but when I put it in a Class
>> > >> file
> for
>> > >> calling it returns the same # for each call.
>> > >> Any ideas why? I'm sure it's something I'll slap myself for but the >> only
>> > >> samples I can find are for calling the Random() within the page, not > a
>> > >> seperate class.
>> > >>
>> > >> --Page--
>> > >> myClass myclass = new myClass();
>> > >> for(int i = 1;i <= 100; i++)
>> > >> {
>> > >> this.myLabel.Text += i + " - " + myClass.GetRandom() + "<br>";
>> > >> }
>> > >>
>> > >> ---- class file
>> > >> public string GetRandom()
>> > >> {
>> > >> Random rnd = new Random();
>> > >> return rnd.Next(1,100));
>> > >> }
>> > >>
>> > >> --
>> > >> Curt Christianson
>> > >> Owner/Lead Developer, DF-Software
>> > >> Site: http://www.Darkfalz.com
>> > >> Blog: http://blog.Darkfalz.com
>> > >>
>> > >>
>> > >>
>> > >
>> > >
>> >
>> >
>>
>>
>
>



Nov 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.