Re: jmlbeud ceararhtcs
Re: jmlbeud ceararhtcs
- Subject: Re: jmlbeud ceararhtcs
- From: "Arthur J. Knapp" <email@hidden>
- Date: Mon, 22 Sep 2003 11:35:38 -0400
>
Date: Sun, 21 Sep 2003 20:50:45 -0400
>
Subject: Re: jmlbeud ceararhtcs
>
From: Deivy Petrescu <email@hidden>
>
This does a good and fast job.
[snip]
It is good and fast. :)
>
to scramble(wordtoscramble)
...
>
repeat with k from lzt to 1 by -1
...
>
set rk to random number from 1 to k
Wherever possible, it's always a good idea to get rid of repeated
calls to scripting addition commands... they're just too darn slow.
Here is an example of calling "random number" just once, and then
mathematically modifying that value repeatedly:
set a to {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
RandomShuffle(a)
a -->
on RandomShuffle(a)
set r to random number -- one osax call
set o to 314159 -- modifies r for each item
set len to a's length
repeat with x from 1 to len
set y to rndUp(r * len) -- an item index
set r to (r * o) mod 1 -- modify r, save decimal part
-- log r -- examine randomness
tell a to set {item x, item y} to {item y, item x}
end repeat
end RandomShuffle
on rndUp(n) -- from Nigel Garvey's aRounderRound
tell n div 1
if it < n then return it + 1
it
end tell
end rndUp
{ 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
"Safe the Nature" --> political graffiti in Prague
}
_______________________________________________
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.