473,654 Members | 3,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(mi n, 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:
StackOverflowEc eption.

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 2202
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.gl obal.net.mt> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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(mi n, 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:
StackOverflowEc eption.

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.gl obal.net.mt> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.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(mi n, 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:
StackOverflowEc eption.

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.gl obal.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(mi n, 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(mi n, max);
--
Jon Skeet - <sk***@pobox.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Curious <th****@mail.gl obal.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(mi n, 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(mi n, max);
--
Jon Skeet - <sk***@pobox.co m>
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
3258
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
3734
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 position using the following code: <code> <!--Node inserted into corrrect position in nodeList(0)-->
6
2762
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. Something this basic can't be so difficult (or impossible) - can it? Thanks. The following roughly shows what I want: class simple { public:
7
2133
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 I never have a recurrence of a number. I could build a table I suppose as I call rand and any number in that table already
6
538
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, what's the difference between method hiding and overriding when they're both still overriding the base method. Thanks
4
2425
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. fAnS.
25
2636
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 produces results with modulo bias. The reasoning is as follows: Because the method random() only produces finitely many possible results, we get modulo bias when the number of possible results is not divisible by the size of the shuffled list.
15
2723
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 pick from a list a random element that satisfies a given property. All or none of the elements may have the property. Most of the time, many of the elements will satisfy the property, and the property is a bit expensive to evaluate. Chance of...
0
8290
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8708
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8489
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.