Re: Random Unique Lists of 12 Numbers
Except that the OP specifically says that the program needs to "create lists untill no more strings can be create." Like the other requirements, it's a bit vague, but as this thread has gone well beyond the point of merely helping him with his homework assignment, it is not unreasonable for us to consider some of the ramifications of both creation and storage.
That said, a 1-for-1 hashing between a random integer and a valid sequence, as you suggest, is almost certainly the ideal solution for sequence generation. I'm sure it could be done by almost everyone that has posted in this thread so far, but doing so and posting the solution here would hand the OP an A+ on a silver platter, and frankly, I don't think he's earned it yet.
Re: Random Unique Lists of 12 Numbers
You can't create more when you run out of memory ^___^
Re: Random Unique Lists of 12 Numbers
If I've read the requirements correctly. The first valid sequence is(sorted) 0,1,2,3,4,5,6,7,8,9,10,11, and the last valid sequence would be 79,80,81,82,83,84,85,86,87,88,89,90(again, sorted).
You can basically store this information in an array of type byte with 12 indices. Dim Numbers(11) as Byte '0 to 11 = 12 indices
Well, I suppose we should start from the beginning, so lets initialize Numbers() to the minimum sequence:
Code:
For x = 1 To 11
Numbers(x) = x
Next x
Then we'll want to check, inside a Do loop, for any duplicates in Numbers(). So do a For x = 0 to 10, and nested inside of that, for loop y = (x + 1) to 11. This will go through every possible combination only once.
Code:
For x = 0 To 10
For y = x + 1 To 11
If Numbers(x) = Numbers(y) Then GoTo AGAIN 'two numbers match, yes... a goto really is the easiest(most efficient) way to break out of nested loops
Next y
Next x
You could also unroll that for more speed(do it without the loops, the much longer way).
Line label AGAIN can be the place in the routine where Numbers() is incremented(and carry over). Just like addition:
Code:
AGAIN: 'increment
Numbers(0) = Numbers(0) + 1
For x = 0 To 10
If Numbers(x) > 90 Then
Numbers(x + 1) = Numbers(x + 1) + 1
Numbers(x) = Numbers(x) - 90
End If
Next x
The Loop on the Do loop should be approximately around here.
I would suggest sorting valid Numbers() prior to storing them. This will make it easier(more efficient) to check for preexisting valid matches.
The bonus to incrementing over randomization is you can easily pause and resume the process at any time, and you're not generating the same sequences repeatedly.
Good luck, as I'm not going to code your entire assignment for you(but I have no problem answering questions). :lol:
Re: Random Unique Lists of 12 Numbers
Homework or Assignment? That was just an assumption so far.
Quote:
Originally Posted by
Lenggries
That said, a 1-for-1 hashing between a random integer and a valid sequence, as you suggest, is almost certainly the ideal solution for sequence generation. I'm sure it could be done by almost everyone that has posted in this thread so far, but doing so and posting the solution here would hand the OP an A+ on a silver platter, and frankly, I don't think he's earned it yet.
That does not include me. I cannot do it.
Quote:
Originally Posted by
FireXtol
Good luck, as I'm not going to code your entire assignment for you(but I have no problem answering questions). :lol:
I have a big problem answering the question.
Please code it here so I (and may be others) can learn, not just the OP.
Re: Random Unique Lists of 12 Numbers
Quote:
Originally Posted by
anhn
Homework or Assignment? That was just an assumption so far.
The OP said "This is a very very hard project for me and i need an A.;(" so we assume it's a school project of some sorts.
Re: Random Unique Lists of 12 Numbers
Quote:
Originally Posted by
baja_yu
.."Just avoid holding it in that way." - Steve Jobs ..
Priceless !