473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 5347

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Malcolm Clift | last post by:
Hi All, I have this so far. import random things = xrange(int(raw_input("choose no of things (1-8)? "))) state =
2
by: Samir | last post by:
I don't know if this is easy or not, I have no clue on how to start it. I have Seven different states. I will be having a form with 7 textboxes, and I will enter 7 different states each time in...
1
by: Videotron | last post by:
Thanks to James A. Fortune in this Newsgroups "Creating random letter combinations", I execute the code he proposes and there were 500,000 combinations generated. This is more than we need to give...
3
by: D r . P r o z a c | last post by:
Hi, I want to identify combinations of letters (a-z)... to make the combination unique, but where the order of these letters is not important. For example: 'er' and 're' should have the same...
13
by: quickcur | last post by:
Suppose I have a function rand() that can generate one integer random number between 0 and 100. Suppose also rand() is very expensive. What is the fastest way to generate 10 different random number...
5
by: Ariel Gimenez | last post by:
Hi i need to generate a random string , can anybody give me an example of how to do it in c# thanks!
2
by: ldpfrog | last post by:
Basically my friend's parents used to log his AIM and email so we made a barbaric version of an encoder that we could type in what we wanted and get random letters out. The only problem is that I did...
24
by: NoName | last post by:
Perl: @char=("A".."Z","a".."z",0..9); do{print join("",@char)}while(<>); !!generate passwords untill U press ctrl-z Python (from CookBook):
1
by: helpfulmaid | last post by:
Hello, I want a function that when it detects the left mouse button is pressed down, will generate and cycle 5 random number/letter combinations as fast as it can in a printed space. If I let off...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.