EDIT: I've removed the base code because the blog erased almost all of it. I'll post the source on my site later and link it.
The first GenerateRandomNumber (the one which accpets no arguments) is used for the second version of this program, the one requiring no repeating digits. The second version of this method (the one accepting arguments) simply returns a random number. Now what is very important is that while the method receiving arguments returns the random number to be used, the one accepting arguments DOES NOT! It actually returns a random number to be selected in a list.
Private Function GenerateRandomNumber(ByVal iLow As Integer, ByVal iHigh As Integer) As Integer
'Randomize number
Return CInt((iHigh - iLow) * Rnd()) + iLow
End Function
The Method
For the first version of this program, all I need to do is grab a random number, and if that number is the same as the previous, re-generate a new number and check it again. This is done above in a while statement.
For the second method, I initially created a list to store the numbers in, then each time I would generate a number, check to see if it was in the list, and if it was I would re-generate a number (similar to the first way and looking at the previous number except now I have a list instead of one number). Now an extreme problem came up, here's the basic example of that problem. Let's assume we're on the first row and can select numbers 0-9 and require 10 numbers. The random generator runs 8 times and in some order produces the numbers 0-8, leaving only the 9 left. Now, the generator will loop over and over and over until it randomly guesses 9, the only remaining available number. Maybe that doesn't seem hard, but it gives the computer a 1/10 chances to guess it. Now repeat that 2 times, how about 38 times?
So, what I implemented was a simple list that stored the numbers from the low to high. If you start the program and type in low as 0 and 9 as high, the program builds 2 lists, one that is completely empty, and one that is filled with each number between those values (0, 1, 2, 3, ..., 9). Now the generate method runs and picks a position (let's say 3) and places that positions value into the blank array (now contains: 2). Next the generate grabs number 0 (now contains: 2, 0). Uh-oh, it again chooses 3! But, since we removed that number from the list, position 3 is now containing the next number in the sequence, 3. Blank array now contains 2, 0, 3. And so on. Then, there's an added part to the generate stating, if the array containing the numbers to choose from only has a size of 1, we only have 1 value left and it will be stored in position 0 so we can automatically assume to return position 0.
Problems
This method has a few problems though. The most immediately concerning, is if the user decides to generate random numbers without repeating digits (method 2) but decides to create more columns than numbers. For example, we have numbers 0-9, but the user requires 11 columns. Our generate will run but will constantly be searching for another number and the array will run out and all sorts of messes occur. I've included protection against this in the final code (via CheckChanged on the check box and a Leave check on the columns box).
Secondly, and I have no idea why this happens, if you run the first method and then run the second method right after, the first row has repeating digits in it. But, if you run the second method more than once, it works fine. I'll look into this error if I have time to revisit this program.
I'll post the code on my website later if you want to grab the source.