Random rnd = new Random();
Random rnd2 = new Random();
int newNo = 0;
for (int i = 0; i < 5; i++)
newNo = rnd2.Next(50);
myEmployeeCollection.Add(new Employee(100 + i,rnd.Next(50),("name" + newNo)));
This[^] 2 page article explains why you're getting the same forboth and the solution is on page 2.
why does everyone act so pricy and rude. If I have to go through all that then why the hell do we have this forum.
Because this forum isn't meant to be a substitute for searching MSDN or exploring the internet. It's here to help when those have failed, otherwise it'd be a load of pointless and unstructured repetition.
You are wrong Dave. If I have to search, I can even find God. Forums are for sharing your knowledge, so that the other person, does not go through time consuming searches.
Instead of going through all these advices you should do what erfi did, be a lil more specific about the answer.
Forums are for helping out when you when the documentation isn't sufficient or you don't know where to look in the documentation. It is not a replacement for using a search engine or reading documentation however much you might want it to be.
You got an answer which gave you enough information to read the documentation. When you read the documentation you will get a lot of other information along with the answer which will give you greater understanding of that area.
Now, take some time to calm down and understand what you are being told and think about why you are being told that. People here want to help. But, we are only prepared to help those who help themselves. It took me a while to understand that, and once I did it started to open up so many doors to me.
I think you need to adjust your attitude towards how forums are used. No forum is a "I'm too lazy, you should give me the answer" area. If you can't find something through searching and doing the hardwork for yourself, then you can come to a forum and ask others for their help. If you are using the Random function, the assumption is that you at least read how to use it in the first place instead of copying the functionality from another source. If you're given a clue as to what to look for, you should go and look that up and read up on it.
... using only one instance of the Random() class.
Random number generators use some formula to generate a sequence numbers that provide the appearance of randomness with a good distribution (i.e. pseudorandom). As you found out, a random number generator starting with the same seed will always produce the same sequence of numbers.
Even with different seeds, there is a maximum length before the sequence begins to repeat (yes, it is a very long time but...). If you run two instances of the same formula with different entry points (seeds) in parallel, there is always a possibility that they are running sufficiently close in the sequence that the distribution between the two sets of numbers is no longer sufficiently random.
Why mess with it? Just use one random number generator.
please can someboby solve this problem for ever?! this is making me crazy. i googled but nothing was found.
there is a "for loop" in my program and i want to break the loop on KeyDown event.
my code is like this :
private bool EXIT;
private void Form1_KeyDown(object sender, KeyEventArgs e)
if (e.KeyCode == Keys.Escape)
EXIT = true;
private void Function()
for (int x = 0; x < Max; x++)
// work on image...
OnPaintBackground(new PaintEventArgs(this.CreateGraphics(),new Rectangle(0,0,Width,eight)));
protected override void OnPaintBackground(PaintEventArgs e)
e.Graphics.DrawImage( image, 0, 0, Width, Height);
when the Esc key is pressed nothing happens.
what i have to do?
FWIW, when I feel the need to capture command keys in a program, I like to do so via the ProcessCmdKey override because I've had issues with those captures in other available handlers. So, you might want to take a look at ProcessCmdKey and see if that will help.
What excactly are you trying to achieve? Is it that once the user has pressed the escape key, you want the application to terminate as soon as possible? Or do you have a longish OnPaint method which you want interrupted when the escape key is pressed?
The first would be much easier. The second I think cannot work without polling for the EXIT variable within the OnPaint procedure everywhere it could be interrupted, and even then I'm not sure it could work. A call to Application.DoEvents won't help cause in OnPaint you're right within handling the windows message queue and have to finish the loop anyway. The keyboard action only puts a message to the end of your form's message queue, which will not be processed before you leave the OnPaint method. Either you do some crazy unmanaged subclassing, or you split your painting logic into "atomic" operations which you instigate (via this.BeginInvoke) from a different thread. In this thread you can capture the EXIT flag set by the main thread via the escape key and if it's true stop pouring BeginInvoke(PaintNextPart) delegates to the main thread.
You need a little more then, of course, and a firm grip of threading and locking mechanisms, or you'll freeze your form.
Once again I humbly beg u to aid my rescue. Is it possible for me to alter the items in a datagrid based on input in a texbox?
onLoad of the form i fill the datagrid with all names from the DB. But, how do i remove items from the list based on the input of the datagrid?
He who goes for revenge must first dig two graves.
This sounds like you load the grid with names from the DB, but do not actually bind it to a DB datasource. If that is true, you might want to consider making this a data bound grid, bind it to a dataview, and then use the RowFilter property of the dataview to manipulate what is shown in the grid.
Last Visit: 31-Dec-99 18:00 Last Update: 31-Jul-21 14:53