Code archives/Miscellaneous/Random Word Generator
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| Generate Words!!! | |||||
Global g$ = ""
Function getLetter(i%)
If i% = 1 Then
a$ = "a"
ElseIf i% = 2 Then
a$ = "b"
ElseIf i% = 3 Then
a$ = "c"
ElseIf i% = 4 Then
a$ = "d"
ElseIf i% = 5 Then
a$ = "e"
ElseIf i% = 6 Then
a$ = "f"
ElseIf i% = 7 Then
a$ = "g"
ElseIf i% = 8 Then
a$ = "h"
ElseIf i% = 9 Then
a$ = "i"
ElseIf i% = 10 Then
a$ = "j"
ElseIf i% = 11 Then
a$ = "k"
ElseIf i% = 12 Then
a$ = "l"
ElseIf i% = 13 Then
a$ = "m"
ElseIf i% = 14 Then
a$ = "n"
ElseIf i% = 15 Then
a$ = "o"
ElseIf i% = 16 Then
a$ = "p"
ElseIf i% = 17 Then
a$ = "q"
ElseIf i% = 18 Then
a$ = "r"
ElseIf i% = 19 Then
a$ = "s"
ElseIf i% = 20 Then
a$ = "t"
ElseIf i% = 21 Then
a$ = "u"
ElseIf i% = 22 Then
a$ = "v"
ElseIf i% = 23 Then
a$ = "w"
ElseIf i% = 24 Then
a$ = "x"
ElseIf i% = 25 Then
a$ = "y"
ElseIf i% = 26 Then
a$ = "z"
EndIf
g$ = g$+a$
End Function
SeedRnd MilliSecs()
.loop
l% = 0
h% = Input$("Words? - ")
While h% <> l%
l% = l%+1
a% = Rand(1,26)
b% = Rand(1,26)
c% = Rand(1,26)
d% = Rand(1,26)
e% = Rand(1,26)
f% = Rand(1,26)
.loop1
If a% = b% Then
b% = Rand(1,26)
Goto loop1
EndIf
If b% = c% Then
c% = Rand(1,26)
Goto loop1
EndIf
If c% = d% Then
d% = Rand(1,26)
Goto loop1
EndIf
If d% = e% Then
e% = Rand(1,26)
Goto loop1
EndIf
If e% = f% Then
f% = Rand(1,26)
Goto loop1
EndIf
getLetter(a%)
getLetter(b%)
getLetter(c%)
getLetter(d%)
getLetter(e%)
getLetter(f%)
Print g$
g$ = ""
Wend
Goto loop |
Comments
| ||
| Interesting Luke :) I hope you take this in good faith, but your coding style is a little "lengthy"...
SuperStrict
Function GetLetter:String()
Return Chr( Rand(97,122) )
End Function
SeedRnd MilliSecs()
Local count% = Input$("Words? - ").ToInt()
Local length% = Input$( "Length? - ").ToInt()
While count
Local word$ = GetLetter()
For Local t:Int = 2 To length
Local a$ = GetLetter()
While( a$ = Mid$( word$, t-1, 1 ) )
a$ = GetLetter()
Wend
word$ :+ a$
Next
Print word$
count :- 1
Wend
Tell me where to go if you like :) I'm sure there's more symantics involved with generating real words but this could be great for generating passwords. |
| ||
Is it something to do that ?
SeedRnd MilliSecs()
Local length=Input("length :")
Local NbWords=Input("Nb Words :")
For w=1 To NbWords
Local word$ = ""
For c=1 To length
word=word+Chr(Rand(Asc("a"),Asc("z")))
Next
Print word
Next
WaitKey()
End
sure, it is a bit "lengthy" ^^ If you want password, it should be better to randomize with number, and upper/lower chars Then , to generate words, maybe some traitments could be interesting, like after a,e,i,o,u,y, always choose some of b,c,d,f,g,h,j,k, etc... |
| ||
SeedRnd MilliSecs()
Dim m(3)
Dim p$(3, 100)
i = 0
j = 0
Repeat
Read pq$
If pq$= "*" Then Exit
If pq$ <> "-"
p$(i, j) = pq$
m(i) = j
j=j+1
Else
i=i+1
j = 0
End If
Forever
Write "You, sir, are nothing but a"
s$ = p$(0, Rand(m(0)))
If Instr("haeiouy", Left$(s$, 1)) > 0 Then Write "n " Else Write " "
Write s$
Write p$(1, Rand(m(1)))
Print p$(2, Rand(m(2))) + "!"
WaitKey
End
Data "br","bl","bw","b","c","ch","d","dr","dw","e","er","el","eg","f","fr","g","gh","gl","h","j","k","kn","l","-"
Data "a","ai","ay","au","e","ea","ee","ei","eo","eu","i","ia","ie","o","oa","oe","oi","oo","ou","u","y","-"
Data "b","d","f","st","n","m","ph","-"
Data "*"
|
| ||
| It just called me a Kn0b!!!!! hahahah! |
| ||
| Warner has the right idea. Ratehr than just spew out individual letters, ideally considerations ought to be made for: 1) Syllables. Each syllable should be applied separately. 2) "Style" of the word (Not sure if there's a correct term for this). i.e. average length, prevalence of vowels or double letters, specific endings (such as 'ing' or 'er' etc. 3) A cleanup process to remive invalid or bad combinations, such as "kk", "bt", "iy" or "hh" etc. The Replace() function is very useful for this cleanup. Simple techniques could be to ensure groups of syllables begin or end in vowels/consonants, by placing this in certain orders can make sure that the words re always "readable". Also, think of 'soft' sounds and 'hard sounds' the syllables create when spoken/written. Some consonants can always follow others, but there are a few consonants that do not. For example: (This list is inexhaustive., but should provide a good starting point.)
; Type 1 consonant groups - Must never be used with other consonants - CAN BEGIN OR END THE WORD
Data "b","c","sc","cs","ch","d","dh","dr","","f","g","gh","gr","gl","gn","h","j","jh","ts",,"x","z","sm","kh","st","ps"
; Type 2 consonant groups - Must never be used with other consonants - CANNOT BEGIN THE WORD
Data "ck","cc","dd","gg","ff","ng","tt","ng","nn","mm","xcl","rr","vv","pth","ght","gth","nx","xx","zz","bb","ths","pths","xc","ghts","nst","lst","ll","lls","rls","lv","tts","rbs","rv","nv","nts","dt","dd","rd","ds","ms","sms","ldt","lds","ss","ht","ntr","pp","pt","pst","rs","rts","rps","rfs"
; Type 3 consonant groups - Must never be used with other consonants - CANNOT END THE WORD:
Data "cr","j","str","vv","gr","gl","kn","xcl","xc","br","bl","nj","jh","lv","shr","rv","nv","dr","dw","cl","chr","kr","vh","ht","tr","ntr","q","pr","pst","pl","pf","pk","kp","gh"
; Type 4 Groups - may appear alone or precede type 5
Data "l","s","n","r","w","m"
;Type 5 May only succede type 4 or appear alone.
Data "p","k","th","ch","qu","ph","d","n","t","s","ths","z","b","ds","ts"
;('Alone' = prefixed or suffixed with vowels) |
Code Archives Forum