 |
cxj98 Level: Trainee
 Registered: 28-05-2007 Posts: 2
|
Randomize generate massive user name database?
I want to generate massive user name database, any ideal?
now for example:
first file named "Firstname.txt", second file named "Surename.txt" ,and third file name "Brithday.txt"
in the firstname.txt have text like:
a
aa
aaa
b
bb
bbb
in the Surename.txt have text like:
1
11
111
2
22
222
in the Birthday.txt have text like:
bitrhday 1, 1, 1990
bitrhday 1, 2, 1991
bitrhday 1,3, 1992
bitrhday 1, 4, 2000
then command button clicked start generate by randomize:
a1 bitrhday 1, 1, 1990
a2 bitrhday 1, 4, 2000
bbb222 bitrhday 1,3, 1992
............
not repeated, generate by randomize.
until user click command button again then it stop, that's it.
open app.path "firstname.txt" & app.path "Surename.txt" & app.path "Brithday.txt.txt" for input as #1
generate result in the txtResult.text or save it in C:\result.txt
thanks!
|
|
28-05-2007 at 06:08 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1616
|
Re: Randomize generate massive user name database?
Well, you could easily get a list of names from a place such as: http://names.mongabay.com/ (copy the text online, paste it into a text file or such).
Although it'd be best to put it in a database I'd think -- quicker access and all. Then you'd just run a query like (mySQL format):
SELECT `name` FROM `firstname` WHERE `id`=' *insert random number here* '
And similar for the surname. All you'd have to do then is combine the first and last names. As far as birthdates and all -- you can get that by creating 3 random numbers (1-12, 1-31, x-2007) a file isn't needed.
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
28-05-2007 at 07:09 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1616
|
Re: Randomize generate massive user name database?
You asked how to generate a massive username database. So unless you were asking "write the program for me", I answered your question.
I gave you the answer of how to do a username database, with selecting a random username/password as well as a place to get a list of names. Since you listed the fake textfile names of "firstname.txt" and "surname.txt" -- that implies actual names, not random generated ones (i.e. "John Smith, December 12, 1894", not "d74hjgjd7 hd7gh4ksh7, January 18, 1980").
Since you were planning on using a text file -- you'd have to read through a random number of lines for each field, ex:
Dim iFree As Integer
Dim lng As Long
Dim lngTotal
Dim i As Integer
Dim sBuffer As String
' Required to get the total number of records in the file --
' if you don't, you won't know what random number to pick last
' (if the file has 5000 records, but you enter up to 100, you'd
' be missing 4500 records from potential names)
iFree = FreeFile
lng = 0
Open "filename.txt" For Input As #iFree
Do Until EOF(iFree)
Line Input #iFree, sBuffer
lngTotal = lngTotal + 1
Loop
Close iFree
' Now pick a random number...
lng = Rnd() * lngTotal + 1
' Now reopen the file to pick that record....
' Based on your option of "until the user says to stop"
Do Until fCommandButtonPressed ' module-level variable set to true once button clicked
Open "filename.txt" For Input As #iFree
Do Until EOF(iFree) Or lngTotal = lng
Line Input #iFree, sBuffer
lngTotal = lngTotal + 1
Loop
Close iFree
Loop
|
Which is why I recommended actually using a database:
Dim adc As ADODB.connection
Dim ars As ADODB.Recordset
Dim randomFirstName
Dim id As Long
' Open database
Set adc = New ADODB.connection
adc.Open 'insert connection string here to open database
' Change TOP 1 to whatever number is desired (1, 5, 1000, etc)
ars.Open "SELECT TOP 1 [firstname], rnd([frequencyrank]) FROM [firstnames] ORDER BY rnd([frequencyrank])"
' Random name (if selecting more than one record, you'd have to loop
' through the results.
randomFirstName = ars.Fields(0)
ars.Close
adc.Close
Set ars = Nothing
Set adc = Nothing
|
Since dates can be done automatically, there's no need to put them in a text file or anything else (since they're random as well):
' Just to make sure only valid dates are used...
Dim rndDate As Date
Dim theMonth As String
Dim theDay As Integer
Dim theYear As Integer
Randomize Timer
theMonth = Int(Rnd() * 12 + 1)
Select Case theMonth
Case 1, 3, 5, 7, 8, 10, 12
theDay = Rnd() * 31 + 1
Case 4, 6, 9, 11
theDay = Rnd() * 30 + 1
Case 2
theDay = Int(Rnd() * 28) ' doesn't take into account leap years
End Select
Do Until theYear > 1900 ' set for the min year
theYear = Rnd() * Year(Now) + 1 ' from 0-current year
DoEvents
Loop
' Just so the month is intrepreted properly:
theMonth = Format(Int(Rnd() * 12 + 1) & "/28/2007", "mmm")
rndDate = theYear & "/" & theMonth & "/" & theDay
MsgBox rndDate
|
' Or for a "simplier" date method
On Error GoTo retry
Dim rndDate As Date
' Just so the month is interpreted properly:
retry:
Randomize Timer
rndDate = Format(Int(Rnd() * 12 + 1) & "/28/2007", "mmm") & "/" & Int(Rnd() * 31 + 1) & "/" & Int(Rnd() * 500 + 1500) ' 0-500 will be randomly generated, so years from 1500-2000 would be returned
MsgBox rndDate
|
[Edited by JLRodgers on 30-05-2007 at 10:10 AM GMT]
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
30-05-2007 at 04:07 PM |
|
|
|
|
 |
 |