• 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
Random seed -- Another strange thing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Random seed -- Another strange thing


  • Subject: Random seed -- Another strange thing
  • From: Daniel Robinson <email@hidden>
  • Date: Sat, 23 Jun 2001 22:03:57 -0400

Christopher et al,

I set out to find if Applesript's Random feature would give duplicates when the
same seed was used.

Yes it does, but it doesn't matter. Nor does using a seed at all.

I have observed:

* Once every try (or so) an identical 12-digit decimal (or two) appears in two
separate lists of 750 random numbers.
(see script one below)

* Once every try (or so) an identical 12-digit decimal (or two) appears in a
single list of 1000 random numbers.
(see script two below)

a) It appears randomly
b) thus is not predictable
c) the number itself does not seem to follow a pattern
d) two identical seeds and two separate loops didn't give a different outcome
than no seed and one loop

Therefore,

I depend upon AppleScript to give a "pseudo-random" number that may repeat an
average of every 750 numbers or so instead of an average of once every half
trillion (999,999,999,999 / 2) as one would expect.

So, in answer to your question, I feel you can reasonably assume that two
different machines would NOT give the same number when seeded by the current
date as triggered by the clock. You probably don't even have to seed.

--Dan

------------------------------------------------------------------------

"Fox, Christopher B" wrote:

> Daniel:
>
> Thanks for the information, but unfortunately my question runs a
> little deeper than you suspect. My problem does not rest in the overall
> distribution of random numbers generated, but with the fundamental default
> seed value for the numbers generated. In short, if I run this generator on
> multiple Macs, what is the likelihood that they will come up with the same
> random number at the same time? If the seed value originates from the system
> date/time, and I am synchronising my Macs via an NTS, it seems to me that
> this possibility may be fairly high. Too high for my script to run properly,
> anyway.
>
> Thanks again.
>
> Christopher Fox

--------------------------------------------------------------------------

(* SCRIPT ONE -- CHECK TWO LISTS FOR DUPLICATES *)


set List1 to {} as list
set List2 to {} as list

-- set seed to 999.9
set HowMany to 750
set x1 to -1
set x2 to -1

--random number seed
repeat HowMany times
set List1 to List1 & (random number)
--end repeat

--random number seed
--repeat HowMany times
set List2 to List2 & (random number)
end repeat

(* check for Duplicates *)

repeat with PointerOne from 1 to HowMany
if List2 contains item PointerOne of List1 then
-- Find the Duplicate
beep
set x1 to PointerOne

repeat with PointerTwo from 1 to HowMany
if item PointerOne of List1 = item PointerTwo of List2 then
set x2 to PointerTwo
end if
end repeat

display dialog "Item " & x1 & " of List 1 : " & item x1 of List1
<opt-CR>
& return & "Item " & x2 & " of List 2 : " & item x2 of List2

end if
end repeat

---------------------------------------------------------------------------

(* SCRIPT TWO -- CHECK SINGLE LIST FOR DUPLICATES *)

set ListOne to {} as list
set HowMany to 1000

repeat HowMany times
set ListOne to ListOne & (random number)
end repeat

set ListTwo to ListOne
set ListTwo to rest of ListTwo -- remove the first item

repeat with PointerOne from 1 to HowMany - 1
set ListTwo to the rest of ListTwo

if ListTwo contains item PointerOne of ListOne then
beep -- Find the Duplicate
repeat with PointerTwo from {PointerOne + 1} to HowMany
if item PointerOne of ListOne = item PointerTwo of ListOne then
display dialog <opt-CR>
"Item " & PointerOne & " of the List : " & <opt-CR>
item PointerOne of ListOne & return & <opt-CR>
"Item " & PointerTwo & " of the List : " & <opt-CR>
item PointerTwo of ListOne
end if
end repeat
end if
end repeat


  • Prev by Date: Re: Why isn't there a constant called finder?
  • Next by Date: Re: Retrospect Client
  • Previous by thread: Re: Need A Force-Quit
  • Next by thread: RE: Random seed -- Another strange thing
  • Index(es):
    • Date
    • Thread