|
-
Jun 22nd, 2010, 03:12 PM
#1
Thread Starter
Lively Member
Random Unique Lists of 12 Numbers
Hello am trying to create a program which will
Generate Lists of unique numbers of 12 between 1-90 until there can be no more unique lists to product
e.g
12 2 4 5 7 9 8 19 90 70 18 56
23 4 8 9 10 12 11 13 60 55 60
-So Creating Multiple Strings of Numbers between 1-90 each string containing only 12 numbers(a string of 12 numbers cannot contain duplicate numbers in it )
-But two strings can contain multiple duplicate numbers as long as the two strings are not the same.(So the program must be able to somehow compare previous generated strings in order to avoid creating an exact same string)
-Sequence of the numbers in each string matter.So the program cannot create a string identical to another already generated but with a different sequence.
Create lists untill no more strings can be create and display a msgbox to stop.
Any ideas?This is a very very hard project for me and i need an A.;(
I cannot do this alone i need help!
Thanks
-
-
Jun 22nd, 2010, 03:15 PM
#2
Re: Random Unique Lists of 12 Numbers
What code do you have so far, what did you already do?
-
Jun 22nd, 2010, 03:22 PM
#3
Thread Starter
Lively Member
Re: Random Unique Lists of 12 Numbers
 Originally Posted by baja_yu
What code do you have so far, what did you already do?
Well no am still thinking how am going to do this.. Its complicated.. and am i bit rusty when it comes to vb6
-
Jun 22nd, 2010, 03:43 PM
#4
Re: Random Unique Lists of 12 Numbers
"Generate Lists of unique numbers of 12 between 1-90 until there can be no more unique lists to product"
First, you need to know at least basic combinatorics in math (permutations and combinations) to be able to do this. If you take into account 1-90 span, with 12 elements in list, I think the number of possible lists will be huge, and checking that there are no duplicate lists might be slow.
If you still want to generate all possible combinations, then you shouldn't be looking into random number generation, it will be faster to use a combinatorics algorithm to generate them all.
Last edited by baja_yu; Jun 22nd, 2010 at 05:46 PM.
Reason: typo
-
Jun 22nd, 2010, 03:46 PM
#5
Thread Starter
Lively Member
Re: Random Unique Lists of 12 Numbers
Yes but its too long to create combinatorics algorithm to generate the list.Computing power is no problem the program will be tested on a new 6 core computer ;]
-
Jun 22nd, 2010, 03:55 PM
#6
Re: Random Unique Lists of 12 Numbers
In that case you still need the basic math to calculate exactly how many possible combinations there are, otherwise the algorithm can go on forever. Pseudo code would look something like this
Code:
Dim lngCombinations As Long
Dim I As Long
Do
For I = 1 To 12
AddItemToList(Int(Rnd * 90 + 1))
Next I
'check that generated list is not identical to all previously generated
If ListIsUnique Then
'add it
lngCombinations = lngCombinations + 1
End If
Loop While lngCombinations < [possible_combinations]
-
Jun 22nd, 2010, 04:03 PM
#7
Re: Random Unique Lists of 12 Numbers
I just refreshed my math studies from college. The number of unique 12 element sequences, without repetition, from a set of 90 elements (1-90) is equal to 90 to the 12th power.
So MS Calc says that for 90^12 you would have in total 282,429,536,481,000,000,000,000 sequences. Generating those on random, while constantly comparing the one generated randomly against all other already generated will take ages to finish, even for a supercomputer.
My suggestion would be to read up on permutations and create an algorithm to generate the sequences in order, rather than endlessly generating random ones.
EDIT: Googling "Visual Basic 6 permutations" I got this: http://www.codeguru.com/vb/gen/vb_mi...mbinations.htm
-
Jun 22nd, 2010, 05:07 PM
#8
Re: Random Unique Lists of 12 Numbers
 Originally Posted by baja_yu
I just refreshed my math studies from college. The number of unique 12 element sequences, without repetition, from a set of 90 elements (1-90) is equal to 90 to the 12th power.
You're actually off by a bit. 90^12 includes permutations with repeating numbers (ie two instances of 12 in teh same sequence), which the OP says is disallowed. However, the OP was vague as to whether or not he wanted permutations or combinations, as the following statement seems to me to be a contradiction:
-Sequence of the numbers in each string matter.So the program cannot create a string identical to another already generated but with a different sequence.
In any case, if he wants permutations, then the total is 90!/(90-12)! = 131,197,375,012,291,112,448,000. If he wants combinations, it is 90!/(12!(90-12)!) = 273,897,571,557,780. However, this does not negate your point that the problem is intractable:
Assuming the lesser of two evils, lets use combinations. Given that each line would take approximately 40 bytes, the output list size would be approximately 10 PETABYTES in length.
I don't know about the OP, but my hard drive doesn't quite hold that. And 6 cores or not, something tells me his classmates will have graduated by the time his program finishes running.
So to the OP, I think one of four things is taking place here:
- You either did not properly communicate to us the actual problem
- Your teacher did not properly communicate the problem with you
- Your teacher is posing a trick question to you
- You're posing a trick question to us
Regardless, your problem as stated has no solution. So if you want any actual help, you'll need to clarify the problem statement. A lot.
Good luck
-
Jun 22nd, 2010, 05:40 PM
#9
Re: Random Unique Lists of 12 Numbers
I might be a bit rusty, but I think that the n^k forumula is for permutations without repetition. For combinations n! / k!(n-k)! is also correct. Permutations return a list of sequences, whereas combinations return a list of sets. The difference being that in sequences the order of items matters (1, 2, 3) is different from (1, 3, 2), whereas with combinations the order of elements is not important so {1, 2, 3} is the same as {1, 3, 2}, {2, 3, 1} etc, thus the much lesser count of combinations than permutations.
But like you said, much clarification is needed on the problem. Still, as you illustrated the size point later which I didn't think of, even with the best possible scenario of all those, the size would still be huge.
EDIT: It really depends on the missing details, and the real purpose of this. If you just want to test the computational power/speed of the CPU, you might be better off looking at some ready made software like SuperPI http://en.wikipedia.org/wiki/Super_PI.
EDIT2: I was wrong with my original formula. n^k is for permutations with repetition, and n! / (n-k)! is without repetitions. Combinations without repetition on the other hand are n! / k! (n-k)!
Last edited by baja_yu; Jun 23rd, 2010 at 08:56 PM.
-
Jun 22nd, 2010, 08:52 PM
#10
Re: Random Unique Lists of 12 Numbers
-
Jun 22nd, 2010, 09:55 PM
#11
Re: Random Unique Lists of 12 Numbers
Think about this. Lets say the resulting size is not a problem, and computational power is not a problem. The total number of unique sequences is what Lenggries calculated to be: 273,897,571,557,780.
Now, assume the random generation algorithm has managed to find: 273,897,571,557,779 of those (one less than total). Now imagine how many times it will need to run doing this:
1. Generate random sequence
2. Do a For loop 273,897,571,557,779 times to compare the newly generated sequence with all the old ones to check if it's not a match to any of them.
3. Repeat.
Even if the For loop in step 2 was lightning fast, I just can't imagine how many times it will do those three steps until it, by random, finally nails the last remaining sequence. 
If there is any chance in the universe of doing this, doing it by random guessing would be the least possible and effective way to get it done. Training monkeys to write and teaching them math so they can write all the combinations manually would probably be faster.
Last edited by baja_yu; Jun 22nd, 2010 at 10:02 PM.
-
Jun 23rd, 2010, 03:40 AM
#12
Re: Random Unique Lists of 12 Numbers
Please don't laugh after viewing this code...
Code:
Option Explicit
Private Sub Command1_Click()
Randomize
Dim myArray(1 To 90) As Integer
Dim num As Integer
Dim i As Long
Dim counter As Integer
Do While counter <= 12
num = Int(Rnd * 90 + 1)
If myArray(num) = 0 Then
myArray(num) = 1
counter = counter + 1
End If
Loop
Dim strOutput As String
For i = 1 To 90
If myArray(i) = 1 Then strOutput = strOutput & " " & i
Next
MsgBox strOutput
End Sub
...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 23rd, 2010, 04:29 AM
#13
Re: Random Unique Lists of 12 Numbers
achileshbc: you can introduce one more array to remember the order of each myarray index, ie. order(counter) = num and then loop through this array instead of For Looping 1 to 90. myarray could be Boolean.
-
Jun 23rd, 2010, 04:44 AM
#14
Re: Random Unique Lists of 12 Numbers
Thanks for the suggestion Merri...
Here's the updated code:
Code:
Option Explicit
Private Sub Command1_Click()
Randomize
Dim myArray(1 To 90) As Boolean
Dim myOrder(11) As Integer
Dim num As Integer
Dim i As Long
Dim counter As Integer
Dim strOutput As String
Do While counter < 12
num = Int(Rnd * 90 + 1)
If myArray(num) = False Then
myArray(num) = True
myOrder(counter) = num
counter = counter + 1
End If
Loop
For i = 0 To 11
strOutput = strOutput & " " & myOrder(i)
Next
MsgBox strOutput
End Sub
...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 23rd, 2010, 06:44 AM
#15
Re: Random Unique Lists of 12 Numbers
OK! That code produce one random sequence of 12 different numbers.
How can you know that an output sequence is not the same as one of the previous ones?
What the OP wants is all the output sequences must be different to each other.
-
Jun 23rd, 2010, 11:02 AM
#16
Re: Random Unique Lists of 12 Numbers
 Originally Posted by anhn
OK! That code produce one random sequence of 12 different numbers.
How can you know that an output sequence is not the same as one of the previous ones?
What the OP wants is all the output sequences must be different to each other.
I missed those lines while reading 
I worked out some code:
Code:
Option Explicit
Private Sub Command1_Click()
'~~~ We are going to produce 4 lines of unique sequence
Dim OutputArray(11) As Byte '~~~ This will hold the numbers generated using the function
Dim strUni(4) As String '~~~ Unicode value(of byte array) of all 4 lines
Dim strOutput As String '~~~ Final result
Dim strTemp As String
Dim n As Long
Dim i As Long
Do While n < 4 '~~~ We are generating 4 lines of sequence
If n > 0 Then
strTemp = StrConv(OutputArray, vbUnicode) '~~~ Getting the unicode string for the generated array values
i = 0
Do While i < 4 '~~~ We are going to check this unicode value with others.
If strTemp = strUni(i) Then '~~~ If it is matched, then the array is shuffled and the checking is restarted.
ShuffleArray OutputArray '~~~ Shuffle the array
strTemp = StrConv(OutputArray, vbUnicode) '~~~ Unicode value of the shuffled array
i = 0 '~~~ Start the checking (loop) from the beginning
Else
i = i + 1
End If
Loop
End If
strUni(n) = mySequence(OutputArray) '~~~ Storing the unicode string of the present byte array values
'~~~ Creating that line of sequence of the present byte array values
For i = 0 To 11
strOutput = strOutput & " " & OutputArray(i)
Next
strOutput = strOutput & vbCrLf '~~~ We are going to start a new line
n = n + 1
Loop
MsgBox strOutput '~~~ Final result
End Sub
Private Function mySequence(ByRef myOrder() As Byte) As String
Randomize
Dim myArray(1 To 90) As Boolean
Dim num As Byte
Dim counter As Integer
Do While counter < 12 '~~~ 12 values (for each line)
num = Int(Rnd * 90 + 1) '~~~ Finding a random number from 1 to 90
If myArray(num) = False Then '~~~ Check if it is already selected
myArray(num) = True '~~~ Marking it as selected number
myOrder(counter) = num '~~~ Storing the number
counter = counter + 1
End If
Loop
mySequence = StrConv(myOrder, vbUnicode) '~~~ Returning the unicode value of this byte array
End Function
' Knuth shuffle (very fast). Thanks to "Ellis Dee" for this shuffle code
Public Function ShuffleArray(pvarArray As Variant)
Dim i As Long
Dim iMin As Long
Dim iMax As Long
Dim lngReplace As Long
Dim varSwap As Variant
iMin = LBound(pvarArray)
iMax = UBound(pvarArray)
For i = iMax To iMin + 1 Step -1
lngReplace = Int((i - iMin + 1) * Rnd + iMin)
varSwap = pvarArray(i)
pvarArray(i) = pvarArray(lngReplace)
pvarArray(lngReplace) = varSwap
Next
End Function
I don't know how efficient it is (I don't think it is efficient at all )....
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 23rd, 2010, 12:09 PM
#17
Re: Random Unique Lists of 12 Numbers
 Originally Posted by akhileshbc
I worked out some code:
I don't know how efficient it is (I don't think it is efficient at all  ).... 
Well I know my code isn't efficient, it never is! 
Creating 32,000 seqs this is about 11 secs faster on my PC (26s VS 37s), if I did it right, probably take a day to create 64K seq its all down hill....
Code:
' requires a listbox named List1 & Knuth shuffle by Ellis Dee
Option Explicit
Private Sub Form_Load()
Randomize
End Sub
Private Sub cmdRun_Click()
Dim Low As Long, High As Long, MaxNums As Long
Dim n As Long, j As Long, i As Long
Dim sTmp As String
Dim t As Single
' How many numbers do we need?
Const NumbersNeeded As Long = 12
'set number range
Low = 1: High = 90
' how many numbers will we need?
MaxNums = High - Low
'produce 32K lines of unique sequence
Dim UniqArray(31999) As String
' dim array to max possible number range
ReDim lngArray(0 To MaxNums) As Long
' CLEAR DISPLAY
List1.Clear
DoEvents
t = Timer
' add range of numbers from low to high to array
For i = Low To High
lngArray(j) = i
j = j + 1 ' increment array position
Next i
BuildSeq:
' shuffle numbers in array
ShuffleArray lngArray ' Knuth shuffle by Ellis Dee
' get numbers from array, add to string
sTmp = vbNullString ' clear old usage of temp string
For i = 0 To NumbersNeeded - 2 'add all array items to string with a space except last one! (-2)
sTmp = sTmp & CStr(lngArray(i)) & " "
Next i
' add last item in array to temp string without space.
sTmp = sTmp & CStr(lngArray(i))
' Search for match in UniqArray
For i = 0 To UBound(UniqArray)
If sTmp = UniqArray(i) Then Exit For
Next i
' if no match then add to UniqArray
If i > UBound(UniqArray) Then
UniqArray(n) = sTmp
List1.AddItem sTmp
n = n + 1 ' increment position for UniqArray
' is array filled yet?
If n > UBound(UniqArray) Then ' all done!
MsgBox Timer - t & " - " & List1.ListCount
Exit Sub
Else ' get another string of 12 non-repeating random numbers.
GoTo BuildSeq
End If
Else ' match found, Try again
GoTo BuildSeq
End If
End Sub
-
Jun 23rd, 2010, 12:56 PM
#18
Re: Random Unique Lists of 12 Numbers
Regular Rnd doesn't give enough variation for results (see anhn's signature about pseudo-random), so:
Code:
Option Explicit
Public Function Random12() As String
Dim Result(0 To 11) As String, Taken(0 To 89) As Boolean
Dim I As Long, R As Long, V As Long
For I = 0 To 11
If I Mod 4 = 0 Then R = RndM * 65610000
V = R Mod 90
Do While Taken(V): V = (V + 1) Mod 90: Loop
Taken(V) = True
Result(I) = V + 1
R = R \ 90
Next I
Random12 = Join(Result)
End Function
Public Function RndM(Optional ByVal Number As Long) As Double
Static X As Long, Y As Long, Init As Boolean
Dim R As Double
If Init And Number = 0 Then
X = (170 * X) Mod 12632251
Y = (171 * Y) Mod 12558383
Else
If Number = 0 Then Number = Timer * 60 Else Number = Number And &H7FFFFFFF
X = (Number Mod 12632251)
Y = (Number Mod 12558383)
If X = 0 Then X = 170
If Y = 0 Then Y = 171
Init = True
End If
R = CDbl(X) / 12632251# + CDbl(Y) / 12558383#
RndM = R - Int(R)
End Function
Private Sub Form_Load()
Debug.Print Random12
End Sub
This does not validate for if same sequence already exists. I find that a matter for another topic, and I also find it next to impossible for this function to generate the very same sequence within, say, a few million calls (and then waiting to be proven wrong...).
Edgemeal: a very minor code length & speed optimization tip: if you Step -1 in a For Loop, you don't need to call UBound for an extra time after the loop to see whether the loop was looped through or not. You'll always get -1 instead (if lower bound is 0).
-
Jun 23rd, 2010, 10:46 PM
#19
Re: Random Unique Lists of 12 Numbers
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 23rd, 2010, 10:47 PM
#20
Hyperactive Member
Re: Random Unique Lists of 12 Numbers
i was thinking of a different approach..if you control how the ID's are made, then you could create an ID that would be the same for every sequence of the same numbers ({1,2,3} would create the same ID as {2,1,3}), which i would think it would speed up your searching.
Code:
Option Explicit
Private Sub Form_Load()
Dim MyData(0 To 11) As Byte
Dim ID As String
Dim i As Long
'you'd put code here to add 12 unique numbers
'you would flag each number like this, but in a loop
'For i = 1 to 12
' Call FlagBit(MyData, MyRandomNumbers(i))
'Next i
Call FlagBit(MyData, 1) 'i just call them individually for my example
Call FlagBit(MyData, 2)
Call FlagBit(MyData, 9)
Call FlagBit(MyData, 89)
Call FlagBit(MyData, 90)
ID = StrConv(MyData, vbUnicode)
'ID would contain your unique string, not readable by the user, but you can change that if needed.
' either by putting 24 bytes as a HEX string or possibly Base64
'then you'd have to search your database or whatever to see if the ID exists already.
End Sub
Private Sub FlagBit(ByRef pArr() As Byte, ByVal pBit As Byte)
Dim MyByt As Byte
MyByt = pBit \ 8
If pBit Mod 8 = 0 Then
MyByt = MyByt - 1
End If
pArr(MyByt) = pArr(MyByt) Or 2 ^ ((pBit - 1) Mod 8)
End Sub
-
Jun 23rd, 2010, 11:11 PM
#21
Re: Random Unique Lists of 12 Numbers
@Billy Conner: Your idea looks cool.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 24th, 2010, 12:58 AM
#22
Re: Random Unique Lists of 12 Numbers
Storage would be another problem... you can squeeze bitmap of 0-90 into 12 bytes (96 bits, 24 hex characters), but you also need to store list info (since numbers in list aren't displayed always in ascending order). That would be another 12 bytes (1 byte per number in list) for a total of 24 bytes (doubled size requirement).
Cost of minimized storage is increased CPU load (bit manipulation/masking, copy memory operations, etc) in order to format as numeric.
As already discussed, array storage is half (array data portion only, 12 bytes, no unique key/flag) but cost is CPU load from iterations.
Last edited by leinad31; Jun 24th, 2010 at 01:01 AM.
-
Jun 24th, 2010, 01:19 AM
#23
Re: Random Unique Lists of 12 Numbers
Don't waste your time on this tough stuff even on Core 64 computer (not mention Core 6) if you don't understand what is behide pseudo-random number generator (PRNG).
It is impractical to check a new generated sequence against an existing unique sequences for this topic because our lives are too short to see it finishes.
There is only one practical way is to generate a series of unique sequences without going back to check whether a sequence already existed or not, ie. each sequence is unique when produced without checking.
So far in this thread, perhaps only Merri can understands the problem as he refered to a thread of mine in CodeBank of 2.5 years ago in that he had a big contribution.
You need to build a PRNG that generates a set of integers (not Integer and not Double) between 0 and at least upto 9012 = 282,429,536,481,000,000,000,000.
The return of a Double value from RndX() or RndM() can have a precision not more than 15 digits that is the precision of the Double data type.
* The native VB Rnd() function can gives only 16,777,216 numbers before it repeats the same sequence.
* The W&H RndX() can produce a set of maximum 27,817,185,604,309 numbers.
* The RndM() seems to produce a set of maximum 158,640,646,210,133 numbers that is still too far behind 9012.
-
Jun 24th, 2010, 02:17 AM
#24
Re: Random Unique Lists of 12 Numbers
Thanks for the valuable info guys...
I'll stop here..
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 24th, 2010, 04:13 AM
#25
Re: Random Unique Lists of 12 Numbers
Now all we need is to have a cameo appearance of the OP
-
Jun 24th, 2010, 04:46 AM
#26
Re: Random Unique Lists of 12 Numbers
I made the scale of RndM larger: see anhn's PRNG thread. It seems to also solve the problem reported by achilleshbc in post #19. Since my strength is more in problem solving than math I don't know the maximum set of numbers generated by the updated function. It uses the Decimal subtype of Variant instead of Double. This will greatly slow the function down, but that is the cost of breaking the limitations.
-
Jun 24th, 2010, 03:17 PM
#27
Re: Random Unique Lists of 12 Numbers
 Originally Posted by akhileshbc
I think its time for upgrading my PC... 
241s, Is that with the CPU in your sig?
Ran your code and got 34.85156 on AMD 550-X2 (unlocked to quad core @ 3.4GHz).
-
Jun 24th, 2010, 08:28 PM
#28
Hyperactive Member
Re: Random Unique Lists of 12 Numbers
 Originally Posted by leinad31
Storage would be another problem... you can squeeze bitmap of 0-90 into 12 bytes (96 bits, 24 hex characters), but you also need to store list info (since numbers in list aren't displayed always in ascending order). That would be another 12 bytes (1 byte per number in list) for a total of 24 bytes (doubled size requirement).
Cost of minimized storage is increased CPU load (bit manipulation/masking, copy memory operations, etc) in order to format as numeric.
As already discussed, array storage is half (array data portion only, 12 bytes, no unique key/flag) but cost is CPU load from iterations.
From what i get, the OP wants to display a list of all sequences of 12 different numbers 1-90, but without using the same exact numbers in a different sequence. i really don't see why the sequence order would be important since there is only one available sequence per group of numbers to be used. He doesn't say the numbers are inputted, as far as i know they could be incremented in the loop. He says sequence matters but he goes on to say that you cannot have the same numbers in a different sequence, that is all he says; nothing about "i need to use the sequence in my program for some other purpose", so i cannot say for sure this isn't what he's looking to do. BUT if the number sequence turns out to be important in whatever it is that he is making, its only 6 more bytes to store instead of the 12 you suggest to hold the info needed to return the numbers to the exact order in which they were presented.(you only need 4 bits to hold 0-11 or 1-12)
anhn has the right idea when it comes to performing this task, which is you don't need to loop to check for duplicate sequences, if you can loop 90^12 times and grab the bits from it(as i do in my example) then you can find every possible non-duplicate sequence that exists in order. Some may argue that vb cannot work with numbers that large but there are ways around the number limitation to get the job done. the only thing stopping you with it is it would still take forever to loop every single sequence, and there is no place large enough for you to store the sequences anywhere.
-
Jun 24th, 2010, 08:36 PM
#29
Re: Random Unique Lists of 12 Numbers
 Originally Posted by Billy Conner
the only thing stopping you with it is it would still take forever to loop every single sequence, and there is no place large enough for you to store the sequences anywhere.
I don't think anybody is saying the the algorithm to do it can't be made. It's just that processing and storage to do it isn't available. There are many ways to go about creating such a list of all possible permutations, some slower some faster, but doing a task like that with random generation is probably the slowest possible. And the fastest still has the storage problem, if nothing else.
The OP is nowhere to be seen. But judging by that it's a school project, it's probably not going to be used at all. The professor probably just wants to test his logic, maths and problem solving skills.
-
Jun 24th, 2010, 09:19 PM
#30
Re: Random Unique Lists of 12 Numbers
 Originally Posted by Merri
I made the scale of RndM larger: see anhn's PRNG thread. It seems to also solve the problem reported by achilleshbc in post #19. Since my strength is more in problem solving than math I don't know the maximum set of numbers generated by the updated function. It uses the Decimal subtype of Variant instead of Double. This will greatly slow the function down, but that is the cost of breaking the limitations.
Thanks for the updated code...
 Originally Posted by Edgemeal
241s, Is that with the CPU in your sig?
Ran your code and got 34.85156 on AMD 550-X2 (unlocked to quad core @ 3.4GHz).
Yeah, the same PC on my signature
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 24th, 2010, 09:21 PM
#31
Re: Random Unique Lists of 12 Numbers
It never ceases to amaze me how a well-defined (not really in this case) conceptual problem brings out the best programmers on this forum. Regardless, I enjoyed reading all of it, and it makes me consider getting back into the classroom to present problems to students that they will report and beg for solutions here.
That way, I would learn at least as must as the students would. 
I'm a bit surprised that the Knuth shuffle did not emerge.
-
Jun 24th, 2010, 09:45 PM
#32
Re: Random Unique Lists of 12 Numbers
 Originally Posted by Billy Conner
From what i get, the OP wants to display a list of all sequences of 12 different numbers 1-90, but without using the same exact numbers in a different sequence. i really don't see why the sequence order would be important since there is only one available sequence per group of numbers to be used. He doesn't say the numbers are inputted, as far as i know they could be incremented in the loop. He says sequence matters but he goes on to say that you cannot have the same numbers in a different sequence, that is all he says; nothing about "i need to use the sequence in my program for some other purpose", so i cannot say for sure this isn't what he's looking to do. BUT if the number sequence turns out to be important in whatever it is that he is making, its only 6 more bytes to store instead of the 12 you suggest to hold the info needed to return the numbers to the exact order in which they were presented.(you only need 4 bits to hold 0-11 or 1-12)
anhn has the right idea when it comes to performing this task, which is you don't need to loop to check for duplicate sequences, if you can loop 90^12 times and grab the bits from it(as i do in my example) then you can find every possible non-duplicate sequence that exists in order. Some may argue that vb cannot work with numbers that large but there are ways around the number limitation to get the job done. the only thing stopping you with it is it would still take forever to loop every single sequence, and there is no place large enough for you to store the sequences anywhere.
Sorry, I don't see how it can be compressed to 6 bytes. Please explain again.
-
Jun 24th, 2010, 10:51 PM
#33
Hyperactive Member
Re: Random Unique Lists of 12 Numbers
 Originally Posted by leinad31
Sorry, I don't see how it can be compressed to 6 bytes. Please explain again.
ok, we know there are 12 numbers that represent 1-90
the bit represented numbers in the original data are always in order.(90 bits)
now we take binary values of our 1-12
0000=0, 0001=1, 0010=2, ... 1100=12
we use them as placement order. 1 would represent the lowest number used(lowest flagged bit), 12 the highest. so we place the binary numbers (1-12) in the order that the originals were in as far as value went.
so if we had values of 1,6,70,45,22,90
you would come up with 1,2,5,4,3,6 order placement.
0001 0010 0101 0100 0011 0110
so six numbers would compress to 3 bytes(24 bits).
of course we have 12 numbers in the real data, so it would just double my example.
-
Jun 24th, 2010, 11:00 PM
#34
Re: Random Unique Lists of 12 Numbers
But you need to save the actual sequence, not just the order of elements in each sequence.
If you've saved: 1,2,5,4,3,6 how would you know if the sequence was: 1,6,70,45,22,90 or 2,7,71,46,23,90?
-
Jun 24th, 2010, 11:09 PM
#35
Hyperactive Member
Re: Random Unique Lists of 12 Numbers
the 6 extra bytes im talking about now are appended to the 12 bytes from my ID variable on my code in post #20
leinad31 said it would double it(making 24 total) if i wanted to know what order they went in, in post #22
-
Jun 24th, 2010, 11:14 PM
#36
Re: Random Unique Lists of 12 Numbers
Ok, the 12 byte way means you either reference the 1-91 bitmap or store the actual number itself giving you 1 byte (pointer to position in bitmap or value itself) x 12 numbers in list.
Doing it the other way around means for each bit in bitmap you need to allocate 4 bits for its position in list, zeroed out if not in list. That would give 4 bits x 90 = 45 bytes of additional storage.
-
Jun 24th, 2010, 11:34 PM
#37
Hyperactive Member
Re: Random Unique Lists of 12 Numbers
 Originally Posted by leinad31
Ok, the 12 byte way means you either reference the 1-91 bitmap or store the actual number itself giving you 1 byte (pointer to position in bitmap or value itself) x 12 numbers in list.
Doing it the other way around means for each bit in bitmap you need to allocate 4 bits for its position in list, zeroed out if not in list. That would give 4 bits x 90 = 45 bytes of additional storage.
ok i'll explain again.
to save the headache im going to work with 6 numbers instead of 12
lets say our numbers in sequence are 8,5,4,3,12,10
i put those in a 12 byte string as explained in post #20. 001110010101 .....rest zeros to 90
ok so now we have 12 bytes that hold the numbers we are using in the sequence, and they are in numerical order.
we want to append more bytes to the 12 to show placement order.
so our sequence was 8,5,4,3,12,10
our placement is 4,3,2,1,6,5
each of the placement numbers become 4 bits each.
so 4,3,2,1,6,5 becomes 0100 0011 0010 0001 0110 0101
thus making 24 bits(3 bytes)
so now we have our ID string(12 bytes) and our Placement string(3 bytes,6 bytes if 12 numbers)
ok we compressed it.
ok so now we retrieve the data back from the original string and we get numbers 3,4,5,8,10,12 in that order. (original was 8,5,4,3,12,10)
but we saved the placement data in the 3 bytes..4,3,2,1,6,5
so the 4th number of "3,4,5,8,10,12" is 8
the 3rd is 5
the 2nd is 4
etc...
only 15 bytes of data used in my example.
there is only 18 bytes of data used total if you have 12 numbers instead of 6..
-
Jun 25th, 2010, 12:27 AM
#38
Re: Random Unique Lists of 12 Numbers
Ok but that would be even more CPU intensive compared to mentioned alternatives (more bit masking required) due to use of 4 bits instead of native 1 byte.
Last edited by leinad31; Jun 25th, 2010 at 12:33 AM.
-
Jun 25th, 2010, 08:50 AM
#39
Re: Random Unique Lists of 12 Numbers
Perhaps, but if we really want to produce a list of all these numbers, then it comes down to balancing time and space requirements. My original estimation was based on using 40 bytes per sequence and requiring about 10 petabytes. Reducing the storage estimation from 40 bytes to 18 bytes using Billy Conner's suggestion reduces the storage cost to about 5 petabytes. That's nothing to sneeze at. Furthermore, the conversion data formats for a single sequence is O(n), where n is the number of elements within a sequence (in this case 12). Happily the fastest method of producing a sequence would also be O(n), which means algorithmically, Billy Connor's method does not increase the complexity at all while reducing storage by 50%. What's not to love about it?
-
Jun 25th, 2010, 09:28 AM
#40
Re: Random Unique Lists of 12 Numbers
You don't need to store them all. Using a PRNG you can initialize at certain point and just go ahead and generate from there. If a more intelligent algorithm is written that by purpose is able to avoid generating same 12 number sequence (in different order) then all you need is knowing the initialization point to get the ones you may want. So instead of making an afterwards check one should write something that avoids the need for the check in the first place.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|