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:32 -0500
- Organization: Society for the Incurably Pompous
Arthur J. Knapp writes:
>
>> Subject: Random Numbers fasters than the osax
>
>> From: email@hidden (Michael Sullivan)
>
>> Date: Wed, 27 Mar 2002 14:07:25 -0500
>
>> 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.
>
script RandomNumber
>
>
property iSeed : {seed} as integer
>
>
property kMult : 31415821
>
property kM : 100000000
>
property kM1 : 10000
>
>
on GetRand()
>
>
set p1 to iSeed div kM1
>
set p0 to iSeed mod kM1
>
>
set q1 to kMult div kM1
>
set q0 to kMult mod kM1
>
>
(((p0 * q1 + p1 * q0) mod kM1) * kM1 + p0 * q0)
>
set iSeed to (result mod kM) + 1 mod kM
>
>
end GetRand
>
>
end script
This looks like it's trying to be an improvement on the algorithm I
ended up finding (of the form X[k-1] = a * X[k] + c), trying to pick a
number for c that's based on the seed and the multiplier.
Obviously it's either not too great an idea, or you transposed something
somewhere, because it's managed to lose a digit of significance (the
last digit is sequential, not pseudo-random). it doesn't suprise me
that this might happen. Zero seemed like a reasonable choice for c to
me, and to the guy who's web page I found this basic algorithm on.
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.