|
i'm not removing at i's place, i'm removing the first place of the collection
|
|
|
|
|
I ran some tests with this code:
public override void Test(int arg) {
int n=10;
int max=1000000;
if (arg==2) { n=10; max=1000; }
if (arg==3) { n=3; max=100; }
Random r=new Random();
int[,] hist=new int[n,n];
int prev=0;
for (int i=0; i< max; i++) {
int j=r.Next(0, n);
hist[prev, j]++;
prev=j;
}
for (prev=0; prev< n; prev++) {
string s="";
for (int j=0; j< n; j++) {
s+=hist[prev, j].ToString().PadLeft(8);
}
log(s);
}
}
and don't see anything wrong with Random, not even over a small [min,max) range.
|
|
|
|
|
Not sure what your problem is - it works as expected for me and as Luc says (and he's not often wrong - if ever. )
Here's a little console app that does what I think you're doing.
Note the bogus variables - you can adjust them to see what happens.
(Gets rid of unnecessary flag but logic is the same. )
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Tester();
Console.ReadLine();
}
public static void Tester()
{
int[] zeroFrequencyLetterList = { 1, 2, 3, 4, 0, 5, 10, 9, 8, 7, 6, 5, 10, 2, 9, 7, 0, 6 };
int decrypted = 0;
char[] encryptionKey = { 'a', 'b', ' ', 'c', 'd', 'e', ' ', ' ', 'f', ' ', 'g' };
Random r = new Random();
for (int i = 0; i < zeroFrequencyLetterList.Count() && decrypted < 25; i++)
{
int randomed;
char aLetter;
do
{
randomed = r.Next(0, zeroFrequencyLetterList.Count());
aLetter = encryptionKey[zeroFrequencyLetterList[randomed]];
Console.WriteLine("{0,3}: {1,3} -> {2}", i, randomed, aLetter );
} while (aLetter == ' ');
decrypted++;
}
}
}
}
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
You create r outside the loop and reuse it. The OP created a new Random instance every time. It is possible that Random has some sort of bias to the first number which it generates, depending on the internal algorithm it uses. It certainly seemed that way when I tried it (completely unscientific, I admit).
|
|
|
|
|
I am pretty sure the seed for the random number is being intialized the same or close enough to skew the results thanks to being in that loop.
Random is actually fairly predictable if you know the seed and the range.
It's how they make those wonderful authenticator programs and keyfabs.
Synch it with one on another site and both will have the exact same number every time.
Check out the seeds comments[^]
|
|
|
|
|
|
In my application i have a picture box and scalablepicturebox control,i need to set image from picturebox to my scalablepictureboxcontrol which is present in form2 and not on mainform but my picturebox is on main form.so what to do ?? so please let me know the piece of code for it.
|
|
|
|
|
Either this is related to
A scrollable, zoomable, and scalable picture box[^] in which case use the "New Message" button at the bottom of the article as it causes the author to receive an email telling him you have a problem.
Or this is "I need to copy information from one form to another and don't know how." In which case see
http://www.codeproject.com/tips/55555/Pass-value-between-forms-using-events.aspx[^]
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
hi i want to filter base on lastname and firstname encode by the user in textbox1 and texbox2.. but i'm having hard time for the right code for this..heres my code but not functioning.. plz help hows the right way..
<br />
<br />
<br />
bindingSource1.Filter = "LASTNAME like '" + textBox1.Text.Trim() + "%'" AND FIRSTNAME like '" + textBox2.Text.Trim() + "%'";<br />
<br />
bindingSource1.Sort = "LASTNAME";<br />
<br />
<br />
<br />
<br />
|
|
|
|
|
What is happening? Or not happening that you expect to happen?
Obviously, it will depend on the content of textBox1 and textBox2, but I imaging they are pretty simple and you have checked them.
Try replacing the textboxes with something you know will match in the DB:
"LASTNAME like 'JON%' AND FIRSTNAME like 'MAT%'"
with a MATTHEW JONES in the DB.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
i want to know to retrieve mails using the pop3 from gmail
|
|
|
|
|
Is Google not working where you are? A simple search using your own words with "C#" tagged on teh end gives thousands of code examples! "retrieve mails using the pop3 from gmail c#" is what I tried...
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
|
hi guys,
Iam try to validate a south african phone number.
I have tried this but it won't work:
Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));
here is an example of numbers I would want to validate:
- 0 74 3720198
- 0 72 3720198
- 27 74 3720198
- +27 74 3720198
Please help me if Iam making a mistake somewhere
I have tried google but no help so far...
Thanks,
Morgan Freeman
|
|
|
|
|
I'm afraid I can't help much with the regex for SA numbers, as I don't know the ins-and-outs of how they are comprised. (Someone else here might be able to help directly), but this [free] tool will speed up validation:
http://www.radsoftware.com.au/regexdesigner/[^]
Also this could be of some help:
http://regexlib.com/Search.aspx?k=south+africa[^]
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
thanks man
I will try your links and thanks alot
Morg
|
|
|
|
|
Your first problem is the spaces between the digits.
Try something a bit simpler, and work your way up to the full expression:
"((0\s)|(27\s))(?<AreaCode>[0-9]{2})(?<LocalNumber>\s[0-9]{7})"
Feed this into Expresso[^] - examines and generates Regular expressions. It's free, and it really helps!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
OriginalGriff wrote: Your first problem is the spaces between the digits
thanks man, with spaces I was just trying to indicate where the full number is branched or divided
I will try your idea and thanks alot
Morg
|
|
|
|
|
hey hey thanks man that program is so cool, I managed
to figure out what was wrong, the right expr:
Regex rx = new Regex("((?:\+27|27)|0)(72|82|73|83|74|84)(\d{7})");
Great one!
|
|
|
|
|
I wish I'd written it!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hi,
First of all, regular expression must be defined using a string, so you have to instanciate it that way :
Regex rx = new Regex("((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7})");
Moreover, as OriginalGriff told you, consider using a tool like Expresso to build and test your regular expressions.
Regards.
|
|
|
|
|
|
Hello!
Recently I have troubles with the following problem.
There's a website (unfortunately it is htpps) where you need to enter 2 values in a form. After you press the button, a POST method is invoked and based on entered values some calculations are made. The final values are dynamically (ajax) put in the corresponding part of the page.
What I need to do is to read this values and store in my database.
My idea was somehow to get source page after all ajax calls are made and grab needed values from it. The problem I have encountered is that I cannot get that kind of source. Using System.Net.WebClient and its UploadStringAsync method I only get the primary source. I tried this source, and some other, async one using UploadStringAsync and UploadStringCompletedEventHandler - results are the same.
Next idea was somehow to capture ajax responses (when certain number is calculated and inserted in the page), because basically that's all I need, the result numbers, but I haven't found any ways to do it.
So, is there a solution to my problem? I forgot to mention that I am trying to code it as a C# project.
|
|
|
|
|
You have been advised to use the ASP.NET forum previously for AJAX questions:
http://www.codeproject.com/Messages/3179251/Re-AJAX-Csharp-and-webpage-source.aspx[^]
The other thing is, getting the values from AJAX based pages isn't any different from normal, unless you have done something out of the ordinary. I suggest you find a good beginners book on this stuff.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Hi,
I have a PictureBox inside a Panel control, the Panel being used to obtain scrollbars for the PictureBox. Having come from Delphi I can't work out a way to make the scrollbars update the position of an image in the PictureBox while the mouse drags the scrollbars (it only updates after the mouse is released).
IIRC with Delphi it was easily done by changing a couple of properties in a TScrollBox component. Does this have to be done manually in the Scroll event handler? Or would it be better to create my own scrolling control for this?
Thanks,
Dave.
|
|
|
|
|