You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Generate random alpha characters in Numbers

Is it possible to generate a sequence of 4 random letters using Numbers?


I need 1,000 cells; each cell needs 4 letters with no duplication of the 4 letter sequence across the cells. I know this can be done with RAND function for numbers, is there a similar option for letters?


Thank you

MacBook Air 13″, macOS 10.15

Posted on Aug 27, 2020 7:49 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 27, 2020 9:07 AM

You can try something like this:




In A2, filled down:


=CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))


In B2, filled down:


=COUNTIF(A,A2)=1


Filter on column be for TRUE to ensure only "unique" values.


If you need the values elsewhere, select the cells in column A, command c to copy, click once in a cell in an existing table, and Edit > Paste Formula Results.


SG


5 replies
Question marked as Top-ranking reply

Aug 27, 2020 9:07 AM in response to chris9771

You can try something like this:




In A2, filled down:


=CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))


In B2, filled down:


=COUNTIF(A,A2)=1


Filter on column be for TRUE to ensure only "unique" values.


If you need the values elsewhere, select the cells in column A, command c to copy, click once in a cell in an existing table, and Edit > Paste Formula Results.


SG


Aug 27, 2020 9:48 AM in response to chris9771

A minimalist script approach could be as follows:


set theChars to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set listSize to length of theChars

set outSeq to {}
set i to 0
repeat until i is 1000
	set pick1 to (random number from 1 to listSize)
	set pick2 to (random number from 1 to listSize)
	set pick3 to (random number from 1 to listSize)
	set pick4 to (random number from 1 to listSize)
	tell theChars to set theSeq to item pick1 & item pick2 & item pick3 & item pick4
	if theSeq is not in outSeq then
		set end of outSeq to theSeq
		set i to i + 1
	end if
end repeat
set text item delimiters to return
set outSeq to outSeq as text
set the clipboard to outSeq
return outSeq -- optional line to view in Results pane



  1. Copy-paste into Script Editor (in Applications > Utilities) -- be sure to scroll right to get the whole script
  2. Make sure Script Editor is listed and checked at System Preferences > Security & Privacy > Privacy > Accessibility.
  3. Click the triangle "run" button.
  4. Click once in a cell in Numbers and command-v or Edit > Paste and Match Style to paste.


SG


Aug 27, 2020 8:53 AM in response to chris9771

CHAR(RANDBETWEEN(65,90)) will give you a random character from A-Z. How you propose to make 4 of them in a cell with no duplicated characters might be the same as what you know to do with numbers. If duplication was not a criteria, you would simply concatenate four of these together with the & operator. I would like to see the solution to the no duplicates part of the problem after you adapt the methodology to this problem.

Generate random alpha characters in Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.