Re: Slow code
Re: Slow code
- Subject: Re: Slow code
- From: "Nigel Garvey" <email@hidden>
- Date: Wed, 13 Sep 2017 10:48:02 +0100
Brian Christmas wrote on Tue, 12 Sep 2017 05:36:56 +1000:
>I’m trying to generate 10,000 serial numbers, as text, in groups of
8,8,6,6
>numbers, with dash separators.
Brian Christmas wrote on Wed, 13 Sep 2017 10:25:30 +1000
>However, I want a reproducable list of codes.
On my machine, the codes are only reproduceable if the random number
seed integer is restricted to nine digits or fewer.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set theSeed to fixit()
random number with seed theSeed
-- Generate serial numbers and gather them into a set to ensure no dupes.
Stop at 10,000 unique entries.
set serialNumbers to current application's class "NSMutableSet"'s new()
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "-"
repeat until (serialNumbers's |count|() is 10000)
tell serialNumbers to addObject:({(random number 89999999) + 10000000,
(random number 89999999) + 10000000, (random number 899999) + 100000, (random
number 899999) + 100000} as text)
end repeat
set AppleScript's text item delimiters to astid
set serialNumbers to serialNumbers's allObjects()
-- Either:
-- set serialNumbers to serialNumbers as list
-- Or:
set serialNumbers to (serialNumbers's componentsJoinedByString:(linefeed)) as
text
on fixit()
set c1 to "743196734015346789"
set c2 to "025694701243831634"
set c3 to "690116383350418453"
set x to text 9 through 11 of c1 & text 2 through 5 of c2 & text 11 through
12 of c3 as integer
return x
end fixit
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden