Pulling Random Names from a list

We are trying to figure out how to pull random names from our data sheet. We have a column of first names and a column of last names. We are trying to be so random the same name should not appear for some time as there are extra warnings in the system to prevent duplicate names.

Here is the code we used;

set myDB to (file:ResourcePath(“Data.xlsx”), type:“excel”, writeable:“Yes”)
set Patientdata to the records of table (“PTData”) of mydb
repeat with each patient of Patientdata
put (item 1 of patient.fname, item 100 of patient.fname) into fnameR
typetext any item of fnameR, return
end repeat

Eggplant would certainly pull random names from the list but would go down in the order on the list and skip some of the name which would come up as a blank. Is there a way to pull a list of random names without the skipping?
I have seen some scripts online to create names but would the names generated be scrambled letters instead of names?
How about something like this:

put patientData into patientDataTmp
repeat the number of items in patientDataTmp
put random(the number of items in patientDataTmp) into itemNo
typetext (item itemNo of patientDataTmp).fname, return
delete item itemNo of patientDataTmp
end repeat
I have seen some scripts online to create names but would the names generated be scrambled letters instead of names?
Yes, they would be scrambled letters.

Excellent, It looks like it is working. There are a few blanks but much better. I will keep troubleshooting.
Thanks so much

I have the script cleaned up and added the last name with the needed comma and space and they are coming across wonderfully. I need to figure how to have different first names and different last name that are on separate rows in order to randomize the names even more.

Thanks for all your help

Just create another random variable to hold the last name index.

Set numOfPatients to the number of items in patientDataTmp
put random(numOfPatients) into firstNameIndex
put random(numOfPatients) into lastNameIndex

Also to ensure names don’t come up too often (so not really random) just save for example the last 10 names into a list - if the name is in the list then get another name, once a suitable name has been found add that name to the list and remove the oldest name.

so now occasionally I will get a blank with only the coma. I am not sure if I need to limit the number of names to look at as it may be looking at blanks on the data sheet.

Just do a check when you grab the name to see if it’s blank, if it is get another name

We were able to simplify the script a bit and pull from the spreadsheet. More of a maintenance issue now but is working.

repeat with each patient of Patientdata by reference

TypeText ControlDown,"1‘",ControlUp,tab,shiftdown, tab, shiftup
wait 1
typetext patient's PTname
typetext tab
typetext patient's SSN
typetext tab
typetext patient's Sex
typetext tab
typetext patient's Age
wait .5
typetext tab, tab, return, return

typetext tab, return
wait 2
DoubleClick "MRN"
typetext controlkey, "c"
log remoteclipboard()
put remoteclipboard() into patient's MRN
Click "ClosePTwindow"
wait 3

end repeat

We use a naming convention for our test patients so we are trying to figure out a way to generate names with numbers in excel. Working through some issues with the VBA errors we are getting.

Thanks for everyone's help

I would probably try and avoid hard coding things like "typeText tab " in
typetext tab
typetext patient’s Sex
typetext tab
typetext patient’s Age
As you might want to change the order of these columns in the future. Consider writing a small handler to get return the age or sex column. But depends on how future proof you want it to be.

Also an idea for a random name generator, instead of assigning single letters to a random number consider assigning syllables like “ler”, “fra” “sm” “let” “bar”
etc and build your name up from them. Could also categorise them (use sepearate lists) so that particular syllables will only appear at the start or end of the word. Like “fra” to make “Frank” or “Francis”.

Anyway hope this helps