Been working on this script as a coding exercise:
display dialog "digits" default answer ""
set digitsnumber to text returned of result
display dialog "places" default answer ""
set placesnumber to text returned of result
set digitsarray to {}
set astidmem to AppleScript's text item delimiters
set repeatcount to 0
set AppleScript's text item delimiters to " "
set placesarray to {}
repeat with i from (count every text item of placesnumber) to 1 by -1
set beginning of placesarray to text item i of placesnumber
end repeat
set AppleScript's text item delimiters to "-"
set xToY to {}
set toDelete to {}
set individualItems to {}
repeat with i from (count of items of placesarray) to 1 by -1
if (count of every text item of item i of placesarray) > 1 then
set beginning of xToY to item i of placesarray as text
set beginning of toDelete to item i of placesarray
end if
end repeat
repeat with i from 1 to count of items of placesarray
if item i of placesarray is not in toDelete then set end of individualItems to item i of placesarray
end repeat
repeat until (count of items of digitsarray) ≥ digitsnumber
set randomfunction to random number
if randomfunction > 0.5 then
repeat
if (count of items of individualItems) = 0 then
set repeatcount to repeatcount + 1
exit repeat
end if
set repeatcount to repeatcount + 1
set randomtext to random number from 1 to (count of items of individualItems) div 1
set placesnumber2 to 1 / (10 ^ (item randomtext of individualItems))
set newdigit to ((random number) div placesnumber2) as text
if ((count newdigit) as text) is equal to (text item randomtext of individualItems) then
set end of digitsarray to " " & newdigit
exit repeat
end if
end repeat
end if
if randomfunction ≤ 0.5 then
repeat
if (count of items of xToY) = 0 then
set repeatcount to repeatcount + 1
exit repeat
end if
set repeatcount to repeatcount + 1
set setnumber to random number from 1 to count of items of xToY
set numlength to ((random number from first text item of item setnumber of xToY to last text item of item setnumber of xToY) div 1) as text
set placesnumber2 to 1 / (10 ^ numlength)
set newdigit to ((random number) div placesnumber2) as text
if ((count newdigit) as text) is equal to numlength then
set end of digitsarray to " " & newdigit
exit repeat
end if
end repeat
end if
end repeat
set AppleScript's text item delimiters to astidmem
display dialog digitsarray as text
return "repeatcount:" & repeatcount & "individualItems:" & individualItems & "xToY:" & xToY
You input how many numbers you want it to output and how many digits you want in the numbers in the format ‘1 3 5-8’ so it will output numbers 1, 3, 5, 6, 7, and 8 digits long. One of the problems is when you put in something such as 5-8, it only outputs numbers 5-7 digits long. Maybe having one with 8 digits is just very rare, all I really know is I haven’t seen any after trying that with hundreds of numbers. The other problem I’m having is that you can’t input the numbers to have more than 9 places. I can’t really see why the code doesn’t allow for this, but it just keeps running. I created this code entirely on my own, other than basic help on how to use certain functions online. I’m fairly proud of it, trying to look at it and remember exactly how it works while I was changing it certainly put a strain on my brain. Any help with these 2 problems would be appreciated. Thanks