471,309 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,309 software developers and data experts.

Creating random letter combinations.

I am looking at creating list of letter combinations.

letters a-h
6 letters per combination
letter can repeat its self in the combination, but not next to its self
and, a series of letter can not repeat in the combinations.

So, ababab, abcabc would not be alowed but, abcbca, abcbac... would all be
alowed.

Does anyone know the code that i could use?

Thanks,

Micheal
Nov 13 '05 #1
7 5204

Micheal Artindale wrote:
I am looking at creating list of letter combinations.

letters a-h
6 letters per combination
letter can repeat its self in the combination, but not next to its self and, a series of letter can not repeat in the combinations.

So, ababab, abcabc would not be alowed but, abcbca, abcbac... would all be alowed.

Does anyone know the code that i could use?

Thanks,

Micheal

yup, I have it right here in my pocket.
Umm... off the top of my head...
create a function that returns a string.
create an array of 6 elements of type byte.
use a rnd() to generate random numbers between your proposed values.
Check as necessary to be sure that the previous value is not equal to
the new value. If it is, redo the random seed until they're different.
Write said value to intArray(i).
In the final step loop through the elements of the array to convert the
values to text using Asc(number). Append the chars to a string
variable. Assign to function name.
Oh, and then if you return your string and you have patterns you don't
want - check for them and rerun the function(?)
Wasn't that fun?
Happy coding.

Nov 13 '05 #2
DFS
Micheal Artindale wrote:
I am looking at creating list of letter combinations.

letters a-h
6 letters per combination
letter can repeat its self in the combination, but not next to its
self and, a series of letter can not repeat in the combinations.

So, ababab, abcabc would not be alowed but, abcbca, abcbac... would
all be alowed.

Micheal,

Your description and examples are contradictory. You say a series of
letters can't repeat in the combinations, but you say 'abcbca' is allowed.
That combination contains the repeated series 'bc'. Regardless, I think I
see what you want.

But I say rather than playing tricks with the ordering and series of
letters, tell us what problem you're trying to solve, and maybe a
better/easier way can be revealed.

Or, use the good algorithms pietlinden gave you in the other reply.

Does anyone know the code that i could use?

Thanks,

Micheal

Nov 13 '05 #3

"DFS" <no****@DFS.com> wrote in message news:KF*****************@fe04.lga...
Micheal Artindale wrote:
I am looking at creating list of letter combinations.

letters a-h
6 letters per combination
letter can repeat its self in the combination, but not next to its
self and, a series of letter can not repeat in the combinations.

So, ababab, abcabc would not be alowed but, abcbca, abcbac... would
all be alowed.

Micheal,

Your description and examples are contradictory. You say a series of
letters can't repeat in the combinations, but you say 'abcbca' is allowed.
That combination contains the repeated series 'bc'. Regardless, I think I
see what you want.

But I say rather than playing tricks with the ordering and series of
letters, tell us what problem you're trying to solve, and maybe a
better/easier way can be revealed.


It is for a game. The game has 8 posts set at cardinal points on a compass
(n,ne,e,se,s,sw,w,nw) The posts are labled a-h. if they go back to a post, I
do not want them going on the same pattern.

Thanks,

Micheal

PS, I do not know how to write code, and i just got access
Nov 13 '05 #4
I personally have never seen a function to do this in VB anywhere
before. But that doens't mean you couldn't write one. If you've never
programmed before, that could be a serious problem. If you didn't
understand my rough outline of how to accomplish it, you might want to
hire someone to do it.

Otherwise, you'll be at it for an eternity. And if you do that, you
should probably make sure you give examples that you know are correct -
because you're depending on someone else figuring out the logic to the
patterns.

have you ever done ANY coding? If not, I doubt it's even worth
explaining, because unless you have a frame of reference (some
familiarity with VB), you wou'dn't understand the explanation anyway.

I would guess that you would have to use InStr() and InStrRev() with
Mid$() to see if you have sequences that repeat and that repeat in
reverse. like [a-b-c]-d-[c-b-a].

Nov 13 '05 #5

<pi********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I personally have never seen a function to do this in VB anywhere
before. But that doens't mean you couldn't write one. If you've never
programmed before, that could be a serious problem. If you didn't
understand my rough outline of how to accomplish it, you might want to
hire someone to do it.
I didnt want to pay anyone to do it.
Otherwise, you'll be at it for an eternity. And if you do that, you
should probably make sure you give examples that you know are correct -
I am sorry, i saw my errors.
because you're depending on someone else figuring out the logic to the
patterns.

have you ever done ANY coding? If not, I doubt it's even worth
explaining, because unless you have a frame of reference (some
familiarity with VB), you wou'dn't understand the explanation anyway.
I dont know any coding.
I would guess that you would have to use InStr() and InStrRev() with
Mid$() to see if you have sequences that repeat and that repeat in
reverse. like [a-b-c]-d-[c-b-a].


ok... I will explain a bit better.

you have 8 letters, a-h.
in the sequence, only have 6 of those letters.
any letter may repeat itself once
no pattern may repeat within the 6 letter conbination
I would like less than 50,000 results.

If you know how to write an SLQ code to do this in MS Access, could you, and
paste it here?

I would like to learn how to do this, eventually.

Once I get it, I will have the fun of putting compass points to the letters.

Thank you,

Micheal
Nov 13 '05 #6
Micheal Artindale wrote:
ok... I will explain a bit better.

you have 8 letters, a-h.
in the sequence, only have 6 of those letters.
any letter may repeat itself once
no pattern may repeat within the 6 letter conbination
I would like less than 50,000 results.

If you know how to write an SLQ code to do this in MS Access, could you, and paste it here?

I would like to learn how to do this, eventually.

Once I get it, I will have the fun of putting compass points to the letters.
Thank you,

Micheal


Here's how I did it using VBA code. I was able to get 50,000+ strings
with no patterns repeating at all. Perhaps someone will post an SQL
only solution.

First, create tblOutput with the following fields:
PathID Autonumber
LetterPath Text (6)

Then run:

'------------Code behind Form
Option Compare Database
Option Explicit

Private Sub cmdGo_Click()
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strSQL As String
Dim lngI As Long

Set MyDB = CurrentDb
strSQL = "SELECT * FROM tblOutput"
Set MyRS = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
For lngI = 1 To 500000
MyRS.AddNew
MyRS("LetterPath") = CreateSequence()
MyRS.Update
Next lngI
MyRS.Close
Set MyRS = Nothing
Set MyDB = Nothing
MsgBox ("Done.")
End Sub
'------------End Code behind Form

'------------Begin Module Code
Public Function CreateSequence() As String
Dim boolValid As String
Dim lngI As Long
Dim strTemp As String
Dim strChar As String
Dim intCharCount(8) As Integer

Randomize
boolValid = False
Do Until boolValid
strTemp = ""
For lngI = 1 To 8
intCharCount(lngI) = 0
Next lngI
For lngI = 1 To 6
strChar = Chr(97 + Int(Rnd() * 8))
'Don't allow two of the same letter in a row or more than two of
the same letter
Do While strChar = Right(strTemp, 1) Or intCharCount(Asc(strChar) -
96) > 1
strChar = Chr(97 + Int(Rnd() * 8))
Loop
strTemp = strTemp & strChar
intCharCount(Asc(strChar) - 96) = intCharCount(Asc(strChar) - 96) +
1
Next lngI
'Validate string
boolValid = True
'Check for pattern repetition, only need six checks
If Mid(strTemp, 1, 2) = Mid(strTemp, 3, 2) Then boolValid = False
If Mid(strTemp, 1, 2) = Mid(strTemp, 4, 2) Then boolValid = False
If Mid(strTemp, 1, 2) = Mid(strTemp, 5, 2) Then boolValid = False
If Mid(strTemp, 2, 2) = Mid(strTemp, 4, 2) Then boolValid = False
If Mid(strTemp, 2, 2) = Mid(strTemp, 5, 2) Then boolValid = False
If Mid(strTemp, 3, 2) = Mid(strTemp, 5, 2) Then boolValid = False
Loop
CreateSequence = strTemp
End Function
'------------End Module Code

This could take a couple of minutes to run.

Then run:
qryLetterPaths:
SELECT TOP 50000 tblOutput.LetterPath FROM tblOutput GROUP BY
tblOutput.LetterPath ORDER BY First(tblOutput.PathID);

Note: This was done using A97. A DAO Reference may need to be added
above ADO to run under later versions of Access. Since 500,000 valid
strings produced over 50,000 distinct strings I decided not to take the
performance hit of checking for duplicates. Watch out for the word
wrap.

James A. Fortune

Nov 13 '05 #7
ji********@compumarc.com wrote:
Micheal Artindale wrote:
ok... I will explain a bit better.

you have 8 letters, a-h.
in the sequence, only have 6 of those letters.
any letter may repeat itself once
no pattern may repeat within the 6 letter conbination
I would like less than 50,000 results.

If you know how to write an SLQ code to do this in MS Access, could

you, and
paste it here?

I would like to learn how to do this, eventually.

Once I get it, I will have the fun of putting compass points to the

letters.


Although my code does solve the problem I'm not satisfied with it.
This turns out to be quite an interesting problem. Even figuring out
how many combinations solve the given conditions is interesting. I
plan on coming back to this problem eventually. One idea is to come up
with code that will add all the possible string combinations into a
table from which to make a random selection. If any of my former math
professors saw the solution I posted they would probably laugh at me.
I should be able to get the strings directly.

James A. Fortune

Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Malcolm Clift | last post: by
2 posts views Thread by Samir | last post: by
3 posts views Thread by D r . P r o z a c | last post: by
13 posts views Thread by quickcur | last post: by
5 posts views Thread by Ariel Gimenez | last post: by
1 post views Thread by helpfulmaid | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.