Re: Slow code
Re: Slow code
- Subject: Re: Slow code
- From: Brian Christmas <email@hidden>
- Date: Tue, 12 Sep 2017 05:36:56 +1000
G’day Takaaki
I’m trying to generate 10,000 serial numbers, as text, in groups of 8,8,6,6
numbers, with dash separators.
I’ve actually got a script that makes the seed number difficult to determine by
reading a text output of the whole script
Random numbers don’t work above 16 digits.
Here’s an early trial, which took 29 seconds.
Just thought there might be some voodoo I could use on it, but my existing
method is the fastest my experiments could come up with
Reading through your site, and link, I’m uncomfortable using skipjack.
Regards
Santa
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set l to ""
set ll to {}
random number 1.0E+16 to 9.99999999999E+16 with seed 1.111111111E+9
repeat with x from 10000 to 20000
set mm to number_to_string(random number from 1.1111111111111E+13 to
9.9999999999999E+13)
set mmm to number_to_string(random number from 1.1111111111111E+8 to
9.9999999999999E+8)
set m to ((x as text) & mm & mmm)
set end of ll to m
end repeat
repeat with temp in ll
set l to (l & (characters 1 through 8 of temp as text) & "-" &
(characters 9 through 16 of temp) & "-" & (characters 17 through 22 of temp) &
"-" & (characters 23 through -1 of temp) & return)
end repeat
on number_to_string(this_number)
set this_number to this_number as string
if this_number contains "E+" then
set x to the offset of "." in this_number
set y to the offset of "+" in this_number
set z to the offset of "E" in this_number
set the decimal_adjust to characters (y - (length of
this_number)) thru ¬
-1 of this_number as string as number
if x is not 0 then
set the first_part to characters 1 thru (x - 1) of
this_number as string
else
set the first_part to ""
end if
set the second_part to characters (x + 1) thru (z - 1) of
this_number as string
set the converted_number to the first_part
repeat with i from 1 to the decimal_adjust
try
set the converted_number to ¬
the converted_number & character i of
the second_part
on error errmsg number errnum
set the converted_number to the
converted_number & "0"
end try
end repeat
return the converted_number
else
return this_number
end if
end number_to_string
> On 12 Sep 2017, at 12:38 am, Takaaki Naganoya <email@hidden> wrote:
>
> It this a serial-code generator or a simple random number generator?
> I don’t know what you need.
>
> We can make simple random number list (item = 10,000) within 0.02 seconds.
> http://piyocast.com/as/archives/4353
>
> We can use serial key generator framework
> http://piyocast.com/as/archives/3797
>
> --
> Takaaki Naganoya
> email@hidden
> http://piyocast.com/as/
>
>> 2017/09/11 14:42、Brian Christmas <email@hidden>のメール:
>>
>> G’day scripters
>>
>> Is there any method of speeding up this handler, please? ATM it’s taking 17
>> seconds.
>>
>> Regards
>>
>> Santa
>>
>> on checkthecode1()
>> set (my EnteringCode) to true
>> say "Please wait" without waiting until completion
>> set l to ""
>> set f1 to 19480822
>> set f2 to 19471206
>> set m to "239360062088" as text
>> random number 1.0E+11 to 9.99999999999E+11 with seed
>> 11111111111111 # Not real seed
>> repeat with x from 1 to 10000
>> set y to x as text
>> set f1 to f1 + (random number from 10 to 100)
>> set f2 to f2 + (random number from 10 to 100)
>> set m to random number from 1.00000000001E+11 to
>> 9.99999999999E+11 as text
>> set temp to number_to_string(m)
>> set l to l & f1 & "-" & f2 & "-" & characters 1 through
>> 6 of temp & "-" & characters 7 through -1 of temp & return as text
>> end repeat
>> set (my PassCodes) to l
>> set (my windowMainFlag) to false
>> windowMainMM's orderOut:me
>> windowCode's makeKeyAndOrderFront:me
>> set focus of Entry1 to true
>> end checkthecode1
>>
>> on number_to_string(this_number)
>> set this_number to this_number as string
>> if this_number contains "E+" then
>> set x to the offset of "." in this_number
>> set y to the offset of "+" in this_number
>> set z to the offset of "E" in this_number
>> set the decimal_adjust to characters (y - (length of
>> this_number)) thru ¬
>> -1 of this_number as string as number
>> if x is not 0 then
>> set the first_part to characters 1 thru (x - 1)
>> of this_number as string
>> else
>> set the first_part to ""
>> end if
>> set the second_part to characters (x + 1) thru (z - 1)
>> of this_number as string
>> set the converted_number to the first_part
>> repeat with i from 1 to the decimal_adjust
>> try
>> set the converted_number to ¬
>> the converted_number &
>> character i of the second_part
>> on error errmsg number errnum
>> set the converted_number to the
>> converted_number & "0"
>> end try
>> end repeat
>> return the converted_number
>> else
>> return this_number
>> end if
>> end number_to_string
>>
>>
>> _______________________________________________
>> 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
>
>
>
>
> _______________________________________________
> 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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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
References: | |
| >Slow code (From: Brian Christmas <email@hidden>) |
| >Re: Slow code (From: Takaaki Naganoya <email@hidden>) |