[Libreoffice] [PATCH] Improve randomisation in 'dissolve' transition.

Neil Brown neilb at suse.de
Tue Sep 28 04:49:56 PDT 2010

Hi libreoffice developers....

Creating a 'bug'


saw no action in 3 years.... Here is hoping that posting the patch to this
new project will :-)

Thanks in advance,

From fd597f0d31131544e1e3e1f3af6de826974ed8f8 Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb at suse.de>
Date: Tue, 28 Sep 2010 21:39:19 +1000
Subject: [PATCH] Improve randomisation in 'dissolve' transition.

The loop for randomizing a list in the dissolve transition is poor.

It randomly chooses two element and swaps them, and does this N/2 times.
Thus a total of N elements are moved.
It is probable that several elements will be swapped multiple times,
leaving it probable that several other elements will not be swapped at all.

This fact is quite visible when transitioning between two very different
slides (e.g. 2 photos).  While there is a lot of randomness, there is a
clearly perceptible top-to-bottom 'wipe' happening at the same time.

So change the loop to provide true randomness.
We randomly choose an element for the last position.
Then randomly choose one of the remaining elements for the second
last position, etc.

Signed-off-by: NeilBrown <neilb at suse.de>

diff --git a/slideshow/source/engine/transitions/randomwipe.cxx b/slideshow/source/engine/transitions/randomwipe.cxx
index af0698d..0d5a0d6 100644
--- a/slideshow/source/engine/transitions/randomwipe.cxx
+++ b/slideshow/source/engine/transitions/randomwipe.cxx
@@ -68,10 +68,9 @@ RandomWipe::RandomWipe( sal_Int32 nElements, bool randomBars )
     m_rect.transform( aTransform );
     // mix up:
-    for ( sal_Int32 i = (nElements / 2); i--; )
+    for ( sal_Int32 pos1 = nElements ; i-- ; )
-        const sal_Int32 pos1 = getRandomOrdinal(nElements);
-        const sal_Int32 pos2 = getRandomOrdinal(nElements);
+        const sal_Int32 pos2 = getRandomOrdinal(pos1+1);
         const ::basegfx::B2DPoint point( m_positions[ pos1 ] );
         m_positions[ pos1 ] = m_positions[ pos2 ];
         m_positions[ pos2 ] = point;

More information about the LibreOffice mailing list