• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Random Numbers fasters than the osax
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random Numbers fasters than the osax


  • Subject: Re: Random Numbers fasters than the osax
  • From: Arthur J Knapp <email@hidden>
  • Date: Fri, 29 Mar 2002 18:21:34 -0500

>> 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.

So after a really annoying Internet search, I found something that
was just barely comprehensible to me, (at least for the purposes of
"porting" to AppleScript). Please let me know if I made any mistakes:

on newRandomNumber(seed)

-- I figure that someone could just make a new script object
-- for every "seed". Otherwise, the user can directly modify
-- the iSeed property.

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

return RandomNumber

end newRandomNumber


set rng to newRandomNumber(123456789)

rng's GetRand() --> 84458770 -- This is interesting, the last digit of
rng's GetRand() --> 200171 -- each of these is sequential, 0, 1, 2...
rng's GetRand() --> 36305392
rng's GetRand() --> 96406833
rng's GetRand() --> 8704894
rng's GetRand() --> 91727975
rng's GetRand() --> 43292476
rng's GetRand() --> 76662797

set rng to newRandomNumber(0 + "987654321") -- I hate scientific notation

rng's GetRand() --> 58412542 -- Same thing here. OK, I screwed up. ;-)
rng's GetRand() --> 63626983
rng's GetRand() --> 8698044
rng's GetRand() --> 93354125
rng's GetRand() --> 80611626
rng's GetRand() --> 12934947
rng's GetRand() --> 79596488
rng's GetRand() --> 19236649


I would really appreciate it if someone could point me in the
direction of some simple pseudo code for RNGs, (as opposed to
platform-optimized implementations or complex mathematical theses).



{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.goodbuddy.net/budco/sware/imscripts.htm>
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.

  • Follow-Ups:
    • Re: Random Numbers fasters than the osax
      • From: "Elias." <email@hidden>
    • Re: Random Numbers fasters than the osax
      • From: Emmanuel <email@hidden>
  • Prev by Date: Re: Is it possible to ...?
  • Next by Date: Re: Quickie Question
  • Previous by thread: Re: Random Numbers fasters than the osax
  • Next by thread: Re: Random Numbers fasters than the osax
  • Index(es):
    • Date
    • Thread