aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs26
1 files changed, 10 insertions, 16 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index ed9bebf..4438395 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -3736,15 +3736,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3736 3736
3737 public LSL_Types.list llListRandomize(LSL_Types.list src, int stride) 3737 public LSL_Types.list llListRandomize(LSL_Types.list src, int stride)
3738 { 3738 {
3739
3740 LSL_Types.list result; 3739 LSL_Types.list result;
3741 Random rand = new Random(); 3740 Random rand = new Random();
3742 3741
3743 int chunkk; 3742 int chunkk;
3744 int[] chunks; 3743 int[] chunks;
3745 int index1;
3746 int index2;
3747 int tmp;
3748 3744
3749 m_host.AddScriptLPS(1); 3745 m_host.AddScriptLPS(1);
3750 3746
@@ -3764,18 +3760,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3764 for (int i = 0; i < chunkk; i++) 3760 for (int i = 0; i < chunkk; i++)
3765 chunks[i] = i; 3761 chunks[i] = i;
3766 3762
3767 for (int i = 0; i < chunkk - 1; i++) 3763 // Knuth shuffle the chunkk index
3764 for (int i = chunkk-1; i >= 1; i--)
3768 { 3765 {
3769 // randomly select 2 chunks 3766 // Elect an unrandomized chunk to swap
3770 index1 = rand.Next(rand.Next(65536)); 3767 int index = rand.Next(i+1);
3771 index1 = index1%chunkk; 3768 int tmp;
3772 index2 = rand.Next(rand.Next(65536)); 3769
3773 index2 = index2%chunkk; 3770 // and swap position with first unrandomized chunk
3774 3771 tmp = chunks[i];
3775 // and swap their relative positions 3772 chunks[i] = chunks[index];
3776 tmp = chunks[index1]; 3773 chunks[index] = tmp;
3777 chunks[index1] = chunks[index2];
3778 chunks[index2] = tmp;
3779 } 3774 }
3780 3775
3781 // Construct the randomized list 3776 // Construct the randomized list
@@ -3797,7 +3792,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3797 } 3792 }
3798 3793
3799 return result; 3794 return result;
3800
3801 } 3795 }
3802 3796
3803 /// <summary> 3797 /// <summary>