Re: Random Numbers fasters than the osax
Re: Random Numbers fasters than the osax
- Subject: Re: Random Numbers fasters than the osax
- From: email@hidden (Michael Sullivan)
- Date: Mon, 1 Apr 2002 16:42:38 -0500
- Organization: Society for the Incurably Pompous
Christopher Nebel writes:
>
On Wednesday, March 27, 2002, at 11:07 AM, Michael Sullivan wrote:
>
>
> the only good changing
>
> number I can think to seed it with is ticks, which is another osax --
>
> and to get real random numbers I'd need to reseed every time, no?
>
That depends on what you mean by a "real" random number. Any sort of
>
purely numerical technique only gives you pseudo-random numbers, but for
>
your application you may not care.
Right. I mispoke. I was only meaning that I wanted reasonably flighty
pseudo-random numbers. I'm looking for a fairly decent number of sig
digits, I don't want to get the same random values every time I run the
program, and I want something close to a normal curve distribution of
results over many iterations. But with a little help from folks here, I
now understand the basic pattern of pseudo-random generators. Seeding
with a changing number like ticks once a the start of the program gives
a good list of numbers.
>
Seeding with the ticks isn't much better, since the seed values are
>
fairly predictable.
You're right, and in fact this means that seeding for every iteration
would be a major problem with the randomness, not just a time problem.
>
You don't need the "ticks" addition to do this --
>
specifying a seed of zero will re-seed from the clock. There are two
>
caveats, however: one, this behavior is broken in AppleScript 1.5.5 and
>
1.6, so "random number with seed 0" will always return the same answer.
>
Second, the clock only changes every 1/60th of a second, so if you call
>
"random number with seed 0" fast enough, you'll get the same answer
>
several times in a row.
Fortunately, the addition appears to generate good enough numbers for my
purposes, the only issue is speed.
Basically, I was just looking to see if anyone had implemented in
vanilla AS, the sort of standard algorithm that might have been used in
your random number osax.
I'm looking at running sims that need a few million random numbers. 1
million iterations of the scripting addition call takes around 12
minutes on my G4/350. 1 million iterations of the vanilla algorithm I
settled on take under a minute. There's a bunch of list manipulation
that my Monte Carlos have to do as well so this only cuts the total time
to about a third, but that's still a major improvement.
Michael
--
Michael Sullivan
Business Card Express of CT Thermographers to the Trade
Cheshire, CT email@hidden
_______________________________________________
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.