Random algorithm
Richard Gaskin
ambassador at fourthworld.com
Fri Nov 14 13:38:36 EST 2008
Dave Cragg wrote:
> On 13 Nov 2008, at 19:38, Richard Gaskin wrote:
>
>> Fortunately, it doesn't. Rev sets the randomSeed to some non-fixed
>> number (a truncated portion of the milliseconds?) each time it starts.
>>
>> This implies that each session starts with a unique seed, so each
>> sequence derived from it will be similarly unique.
>
> This occurred to me last night while reviewing my comment on your
> seeding method. Does a different randomSeed guarantee a different
> random sequence in the same way that the same seed produces the same
> sequence?
"Guarantee" is a tough claim to verify, since it's possible that even a
truly random sequence might by chance appear as a repeated pattern. :)
But to test this I made a simple test stack with a button and two
fields, with this in the button script:
on mouseUp
put empty into fld 1
put empty into fld 2
--
-- Test 1: psuedo-random randomSeed:
repeat 2
set the randomseed to random(444444)
repeat 10
set the randomSeed to random(444444)
put random(10) &cr after fld 1
end repeat
put cr&cr after fld 1
end repeat
--
-- Test 2: fixed randomSeed:
repeat 2
set the randomseed to 10
repeat 10
set the randomSeed to random(10)
put random(10) &cr after fld 2
end repeat
put cr&cr after fld 2
end repeat
--
end mouseUp
Results:
Field 1:
1 5 10 8 8 6 4 4 9 3
1 4 10 10 9 3 9 7 3 9
Field 2:
1 1 6 8 1 1 6 8 1 1
1 1 6 8 1 1 6 8 1 1
This seems to support the hypothesis that using a fixed randomSeed will
result in the same sequence being generated even if you later set the
randomSeed using random(), but changing the randomSeed to a non-fixed
number changes the resulting sequence.
--
Richard Gaskin
Managing Editor, revJournal
_______________________________________________________
Rev tips, tutorials and more: http://www.revJournal.com
More information about the use-livecode
mailing list