RE: Random seed -- Another strange thing
RE: Random seed -- Another strange thing
- Subject: RE: Random seed -- Another strange thing
- From: "Fox, Christopher B" <email@hidden>
- Date: Mon, 25 Jun 2001 10:09:26 -0400
Thanks for your research Dan. I've also come up with an alternate method for
increasing the "uniqueness" of the "random" filenames generated by my
script. I am grabbing the owner name initials from FileSharing Commands.
The owner name initials, plus the five character randomly generated string
should provide enough uniqueness in naming so that I do not have collisions
when 200 users use this script to copy files to a single folder on a single
server.
Thanks again.
Christopher Fox
>
----------
>
From: Daniel Robinson
>
Reply To: email@hidden
>
Sent: Saturday, June 23, 2001 10:03 PM
>
To: Fox, Christopher B; Applescript List
>
Subject: Random seed -- Another strange thing
>
>
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
>
>
**************************************************************************
The Information transmitted herewith is sensitive information intended only
for use to the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon, this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.