Jump to content
Xtreme .Net Talk

Jibrohni

Avatar/Signature
  • Posts

    28
  • Joined

  • Last visited

Everything posted by Jibrohni

  1. Thanks for your time on this I really appreciate it. This will work much better than the way I was grinding out the result. I feel your pain too. I've just built a new upgraded pc trying to save money, HA! It's so far cost me £900 and I'm just about to buy a graphics card. (And this didn't include a screen). Oh well, I'll have to make sure I get my moneys worth...
  2. Hey all, I'm just starting out using C# and am trying to learn by converting a program I've started in VB to C#. Sadly I'm stuck early on with trying to generate an array of 52 randomly ordered integers. I have it working but fear that I'm not doing a tidy job. The routine seems very sluggish as opposed to it running in VB. Please can anyone advise on a better way to do this than my method below please? I'm using a goto statement which I have a bad feeling about and it's also doing a fair few iterations that can most likely be avoided. Even so, it shouldn't be taking my nice new i5 processor 3-4 seconds?? private int RandomNumber(int min, int max) { Random random = new Random(); return random.Next(min, max); } public int[] GenerateDeck() { int[] DECK = new int[52]; //creates an array to hold thegenerated deck int iCounter = 1; do { Start: int rndNum = RandomNumber(0, 52); if (DECK[rndNum] == 0) { DECK[rndNum] = iCounter; iCounter++; } else goto Start; } while (iCounter < 53); return DECK; } private void btnGenerate_Click(object sender, EventArgs e) { GenerateDeck(); } I really appreciate your time. P.S. I like the efficiency and neatness of C# coding. Shame I'm crap at it...
×
×
  • Create New...