Generating numbers-VBForums
Results 1 to 4 of 4

Thread: Generating numbers

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Generating numbers

    Hello is there some algorithm which can generate random numbers in int[,](two dimentional array).
    Let's say I have these numbers :

    lets say that the blue circle is the current position in the array where the loop have to enter a number,but first I have to check all four directions(current =>down,up,left,right) and if the random number don't exist in these four directions then to enter it in.
    My problem is that I don't know how to check all the drections without throwing a error and I don't want to use try & catch.

    Thx in advance.

  2. #2
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    677

    Re: Generating numbers

    So what happens if you are at 3 instead of 5? How would that look? Or would you only evaluate 6 and 8, instead of the 4 on the other far end? Otherwise this is pretty simple. The number above it, is just the index of the number on the bottom + 1, and then you'd just take the element[current_index - 1] and element[current_index + 1] to get the sides. Otherwise, if the element index is 0 or the upperbound index, check as to whether to return the last index or the first index for the opposite end if that's the way you're going...

    You don't need a 2D array to do this. Unless that top row of numbers, is not always going to be sequential and starting from 1, counting by 1, all the time. But even then, I don't see the requirement for a 2D array.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    VB.NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Posts
    231

    Re: Generating numbers

    Well the contest want to do it this way , I mean using 2D array.
    But what worries now me is that the 2d array will be 1000x1000 which is a lot
    And I am not sure that there is a way to write such thing and make the code to complete the action for 3 seconds

  4. #4
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    677

    Re: Generating numbers

    A 2D array wouldn't be 1000x1000 unless you have some awkward structure, it would be 1000+1000, if your concept is for the 2D array a structure like this:
    Code:
    {{1,2,3,4,5},{4,7,8,3,5}}
    I don't even see the point in that...
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    VB.NET Programming (2012 - Present)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.