473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Uniform(...) method

Hi,

I am writing a class Distribution that inherits from Random class

public class Distribution : System.Random
{
public int Uniform(int min, int max)
{
return this.Uniform(min, max);
}

}

Now I wrote the new Uniform method, and I'm acessing the base method
having this name.

When I execute the application, a runtime error is given:
StackOverflowEception.

Distribution d = new Distribution();
d.Uniform(0, 5);

Can someone give some help regarding this method, because I cannot find
anything about it on the net.

Thanks in Advance

Nov 17 '05 #1
4 2188
Hi,
you are calling a recursive function infinitely so it gives stackoverflow
message. this.Uniform means the Uniform function of the class you are in
right now, and since u r already in Uniform function a recursive call to it
starts, which goes on untill stack overflows. You should fix this.

Ab.
http://joehacker.blogspot.com
"Curious" <th****@mail.global.net.mt> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi,

I am writing a class Distribution that inherits from Random class

public class Distribution : System.Random
{
public int Uniform(int min, int max)
{
return this.Uniform(min, max);
}

}

Now I wrote the new Uniform method, and I'm acessing the base method
having this name.

When I execute the application, a runtime error is given:
StackOverflowEception.

Distribution d = new Distribution();
d.Uniform(0, 5);

Can someone give some help regarding this method, because I cannot find
anything about it on the net.

Thanks in Advance

Nov 17 '05 #2
Hello,

In case you want to make this work then you need to put some logic in the
Uniform method to exit out of the recursive loop. Example you could use a
counter to let this run for a certain number of times and then exit out of
the loop.

Hope this helps...
Ramneek

"Abubakar" wrote:
Hi,
you are calling a recursive function infinitely so it gives stackoverflow
message. this.Uniform means the Uniform function of the class you are in
right now, and since u r already in Uniform function a recursive call to it
starts, which goes on untill stack overflows. You should fix this.

Ab.
http://joehacker.blogspot.com
"Curious" <th****@mail.global.net.mt> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi,

I am writing a class Distribution that inherits from Random class

public class Distribution : System.Random
{
public int Uniform(int min, int max)
{
return this.Uniform(min, max);
}

}

Now I wrote the new Uniform method, and I'm acessing the base method
having this name.

When I execute the application, a runtime error is given:
StackOverflowEception.

Distribution d = new Distribution();
d.Uniform(0, 5);

Can someone give some help regarding this method, because I cannot find
anything about it on the net.

Thanks in Advance


Nov 17 '05 #3
Curious <th****@mail.global.net.mt> wrote:
I am writing a class Distribution that inherits from Random class

public class Distribution : System.Random
{
public int Uniform(int min, int max)
{
return this.Uniform(min, max);
}

}

Now I wrote the new Uniform method, and I'm acessing the base method
having this name.


No you're not - you're accessing the method you're calling it from. I
suspect you meant:

return base.Uniform(min, max);
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Curious <th****@mail.global.net.mt> wrote:
I am writing a class Distribution that inherits from Random class

public class Distribution : System.Random
{
public int Uniform(int min, int max)
{
return this.Uniform(min, max);
}

}

Now I wrote the new Uniform method, and I'm acessing the base method
having this name.


No you're not - you're accessing the method you're calling it from. I
suspect you meant:

return base.Uniform(min, max);
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


That was what I thought he wanted also, except that I cannot find a Uniform
method on the System.Random class (either in 1.1 or 2.0), so it is *very*
unclear what the OP was trying to do!
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Karl Pech | last post by:
Hi, I got a task there I have to compute pi using the Method above. So I wrote the following program: --- import random import math
1
by: chris yoker | last post by:
hiya, I succesfully return a "nodeList" thru the "xmlDoc.SelectNodes" method. This nodeList is taken from a repetitive, uniform xml doc. I can successfully append a child node at the correct...
6
by: max reason | last post by:
A method in one of my classes needs to call one of 256 other methods in the same class based on an unsigned 8-bit value (0x00 to 0xFF). How is this done? Everything I try generates errors. ...
7
by: aegis | last post by:
is there any trickery that can be done with rand() so that it generates a uniformly distributed sequence? Suppose that I want any thing in the range m..n (inclusive) to be generated such that...
6
by: harrylmh | last post by:
Hi, I'm learning C# and I just don't quite understand the need for polymorphism. why do we need to use it? how does a base class variable holding a derived class instance do any good? Also,...
4
by: fAnSKyer | last post by:
When using random we can get a uniform data sample. But how to transfer this sample in to a Guassion Sample? Thanks? Did C or C++ provide any function to do this? Thanks a lot. Cheers....
25
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py...
15
by: caca | last post by:
Hello, This is a question for the best method (in terms of performance only) to choose a random element from a list among those that satisfy a certain property. This is the setting: I need to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.