diff options
author | Charles Krinke | 2008-07-27 16:21:51 +0000 |
---|---|---|
committer | Charles Krinke | 2008-07-27 16:21:51 +0000 |
commit | e4ef7748753489792e86f14fa7d8bace37ef8590 (patch) | |
tree | 7019861f2a9d1d9109a67c2d1735ca3bf0d1ebb4 /OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |
parent | Mantis#1817. Thank you kindly, sacha magne, for a patch that: (diff) | |
download | opensim-SC_OLD-e4ef7748753489792e86f14fa7d8bace37ef8590.zip opensim-SC_OLD-e4ef7748753489792e86f14fa7d8bace37ef8590.tar.gz opensim-SC_OLD-e4ef7748753489792e86f14fa7d8bace37ef8590.tar.bz2 opensim-SC_OLD-e4ef7748753489792e86f14fa7d8bace37ef8590.tar.xz |
Mantis#1831.Thank you kindly, Francis for a patch that addresses:
Not all combinations of list order equally likely with llListRandomize()
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 26 |
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> |