• 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: jmlbeud ceararhtcs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: jmlbeud ceararhtcs


  • Subject: Re: jmlbeud ceararhtcs
  • From: "Arthur J. Knapp" <email@hidden>
  • Date: Tue, 23 Sep 2003 10:53:07 -0400

> Date: Mon, 22 Sep 2003 11:35:38 -0400
> Subject: Re: jmlbeud ceararhtcs
> From: "Arthur J. Knapp" <email@hidden>

> Here is an example of calling "random number" just once, and then
> mathematically modifying that value repeatedly:

And here are some better, and certainly easier to use methods:


(* One osax call during compilation, and any value to
* modify it:
*)
property rand_previous : random number
property rand_modifier : 314159

on Randy()
set rand_previous to rand_previous * rand_modifier mod 1
end Randy

on RandomIndex(len)
return Randy() * len div 1 + 1
end RandomIndex

on RandomNumber(i, j)
return Randy() * (j - i + 1) div 1 + i
end RandomNumber

on RandomShuffle(a)
script o
property p : a
end script
set len to a's length
repeat (len div 2) times
set i to RandomIndex(len)
set j to RandomIndex(len)
set t to o's p's item i
set o's p's item i to o's p's item j
set o's p's item j to t
end repeat
end RandomShuffle


(* Speed Test:
*)
set iterations to 100000 -- 100,000

set t0 to current date
repeat (iterations) times
random number
end repeat
set t1 to current date
repeat (iterations) times
Randy()
end repeat
set t2 to current date

{t1 - t0, t2 - t1} --> {104, 3}


(* Distribution Test:
*)
set a to {}
repeat 100 times
set a's end to 0
end repeat

repeat 10000 times -- 10,000
set i to RandomNumber(1, 100)
set a's item i to (a's item i) + 1
end repeat

a -->
(* {92, 104, 105, 117, 96, 91, 91, 92, 95, 99,
91, 94, 109, 114, 111, 94, 108, 108, 112, 108,
109, 94, 114, 94, 99, 94, 101, 97, 90, 114,
105, 93, 95, 102, 104, 99, 107, 100, 88, 97,
108, 110, 99, 110, 100, 78, 99, 101, 91, 107,
90, 91, 107, 96, 79, 107, 89, 93, 101, 116,
99, 81, 105, 96, 96, 112, 97, 109, 111, 103,
104, 82, 97, 109, 100, 103, 88, 106, 100, 92,
105, 98, 97, 94, 100, 97, 99, 97, 96, 100,
116, 88, 112, 110, 100, 103, 90, 117, 71, 121}
*)


Michael Sullivan had had a more robust and fully featured means
of quickly and repeatedly generating random numbers, but I seem to
have misplaced his script, and AppleMods, (where he had released
it), doesn't seem to be in existance any more. I am also unable to
get a hold of Greg Strange. Does anyone know anything about him?



{ Arthur Knapp, of <http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m

Philadelphia : Roxborough / Manayunk / East Falls / Andorra
}
_______________________________________________
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: jmlbeud ceararhtcs
      • From: Deivy Petrescu <email@hidden>
  • Prev by Date: Image thumbnails question
  • Next by Date: Re: Wierd error
  • Previous by thread: Re: jmlbeud ceararhtcs
  • Next by thread: Re: jmlbeud ceararhtcs
  • Index(es):
    • Date
    • Thread