Re: Random Numbers fasters than the osax
Re: Random Numbers fasters than the osax
- Subject: Re: Random Numbers fasters than the osax
- From: Arthur J Knapp <email@hidden>
- Date: Thu, 28 Mar 2002 20:05:51 -0500
>
Subject: Random Numbers fasters than the osax
>
From: email@hidden (Michael Sullivan)
>
Date: Wed, 27 Mar 2002 14:07:25 -0500
>
I've just had the brilliant idea to write some ad hoc monte carlo sims
>
in applescript since I'm getting really comfortable with it. For the
>
kind of accuracy I'm looking for, it has the potential to be plenty fast
>
enough, except for one thing. I need to generate a lot of random
>
numbers -- that's an osax which takes about 10 times as long as a
>
vanilla instruction, making it *just* slow enough that a useful sim for
>
what I'm looking at might take an hour or two to run, instead of maybe
>
10 minutes.
>
>
That's not a huge deal, but I'm wondering if one of you math wiz folks
>
has a vanilla random number generator handy, or a suggestion on how to
>
build one.
This is going to look really silly to the "math wiz folks", but the
following handler does seem slightly faster than the random osax
command:
(* A very simple random number generator, (for obtaining a
* specified range), that does not use any scripting
* addition commands.
*)
on RandomRange(n, m)
set r to ""
repeat ("" & m)'s length times
set r to r & "0123456789"'s some item
end repeat
return ((0 + r) mod m) + n
end RandomRange
set t0 to current date
repeat 5000 times
set x to RandomRange(1, 1000)
end repeat
set t1 to current date
repeat 5000 times
set x to random number from 1 to 1000
end repeat
set t2 to current date
{t1 - t0, t2 - t1}
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://www.appleklub.cz/~koudelka/home.shtml>
on error number -128
end try
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.