diff --git a/OpenSim/Framework/MultipartForm.cs b/OpenSim/Framework/MultipartForm.cs
index 7a13e8b21c..35cf82adb3 100644
--- a/OpenSim/Framework/MultipartForm.cs
+++ b/OpenSim/Framework/MultipartForm.cs
@@ -129,11 +129,10 @@ namespace OpenSim.Framework
private static string Boundary()
{
- Random rnd = new Random();
string formDataBoundary = String.Empty;
while (formDataBoundary.Length < 15)
- formDataBoundary = formDataBoundary + rnd.Next();
+ formDataBoundary = formDataBoundary + Random.Shared.Next();
formDataBoundary = formDataBoundary.Substring(0, 15);
formDataBoundary = "-----------------------------" + formDataBoundary;
diff --git a/OpenSim/Framework/ThreadSafeRandom.cs b/OpenSim/Framework/ThreadSafeRandom.cs
index 58853e6052..08fd2860c8 100644
--- a/OpenSim/Framework/ThreadSafeRandom.cs
+++ b/OpenSim/Framework/ThreadSafeRandom.cs
@@ -25,6 +25,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+// legacy Use Random.Shared instead
+
using System;
namespace OpenSim.Framework
@@ -35,37 +37,38 @@ namespace OpenSim.Framework
///
public class ThreadSafeRandom : Random
{
+ private readonly object mainLock = new();
public ThreadSafeRandom() : base() {}
public ThreadSafeRandom(int seed): base (seed) {}
public override int Next()
{
- lock (this)
+ lock (mainLock)
return base.Next();
}
public override int Next(int maxValue)
{
- lock (this)
+ lock (mainLock)
return base.Next(maxValue);
}
public override int Next(int minValue, int maxValue)
{
- lock (this)
+ lock (mainLock)
return base.Next(minValue, maxValue);
}
public override void NextBytes(byte[] buffer)
{
- lock (this)
+ lock (mainLock)
base.NextBytes(buffer);
}
public override double NextDouble()
{
- lock (this)
+ lock (mainLock)
return base.NextDouble();
}
}
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 06bebad887..34b7ebda54 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -166,7 +166,6 @@ namespace OpenSim.Framework
}
private static uint nextXferID = 5000;
- private static readonly Random randomClass = new ThreadSafeRandom();
// Get a list of invalid file characters (OS dependent)
private static readonly string regexInvalidFileChars = $"[{new String(Path.GetInvalidFileNameChars())}]";
@@ -412,9 +411,10 @@ namespace OpenSim.Framework
}
}
+ // legacy, do not use
public static Random RandomClass
{
- get { return randomClass; }
+ get { return Random.Shared;}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs
index 9a2ab410c3..a57a3e71d9 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/UpdateItemAsset.cs
@@ -335,7 +335,7 @@ namespace OpenSim.Region.ClientStack.Linden
if (m_dumpAssetToFile)
{
- Util.SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data);
+ Util.SaveAssetToFile("updateditem" + Random.Shared.Next(1, 1000) + ".dat", data);
}
response.StatusCode = (int)HttpStatusCode.OK;
@@ -417,7 +417,7 @@ namespace OpenSim.Region.ClientStack.Linden
if (m_dumpAssetToFile)
{
- Util.SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
+ Util.SaveAssetToFile("updatedtaskscript" + Random.Shared.Next(1, 1000) + ".dat", data);
}
// m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
index 02e7f63397..3dfe333e3a 100755
--- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs
@@ -375,8 +375,7 @@ namespace OpenSim.Region.ClientStack.Linden
m_ids[agentID]++;
else
{
- Random rnd = new Random(Environment.TickCount);
- m_ids[agentID] = rnd.Next(30000000);
+ m_ids[agentID] = Random.Shared.Next(30000000);
}
}
}
@@ -402,8 +401,7 @@ namespace OpenSim.Region.ClientStack.Linden
m_ids[agentID] = -m_ids[agentID];
else
{
- Random rnd = new Random(Environment.TickCount);
- m_ids[agentID] = -rnd.Next(30000000);
+ m_ids[agentID] = -Random.Shared.Next(30000000);
}
}
}
@@ -417,8 +415,7 @@ namespace OpenSim.Region.ClientStack.Linden
m_ids[agentID]++;
else
{
- Random rnd = new Random(Environment.TickCount);
- m_ids.Add(agentID, rnd.Next(30000000));
+ m_ids.Add(agentID, Random.Shared.Next(30000000));
}
}
}
@@ -518,8 +515,7 @@ namespace OpenSim.Region.ClientStack.Linden
{
if (element == null && negativeID)
{
- Random rnd = new Random(Environment.TickCount);
- m_ids[pAgentId] = rnd.Next(30000000);
+ m_ids[pAgentId] = Random.Shared.Next(30000000);
}
else
m_ids[pAgentId] = thisID + 1;
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
index 19cfbbde23..3cc8a99dd1 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/OpenSimUDPBase.cs
@@ -105,12 +105,6 @@ namespace OpenMetaverse
}
#region PacketDropDebugging
- ///
- /// For debugging purposes only... random number generator for dropping
- /// outbound packets.
- ///
- private Random m_dropRandomGenerator = new Random();
-
///
/// For debugging purposes only... parameters for a simplified
/// model of packet loss with bursts, overall drop rate should
@@ -135,7 +129,7 @@ namespace OpenMetaverse
///
private bool DropOutgoingPacket()
{
- double rnum = m_dropRandomGenerator.NextDouble();
+ double rnum = Random.Shared.NextDouble();
// if the connection has been idle for awhile (more than m_dropResetTicks) then
// reset the state to the default state, don't continue a burst
diff --git a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
index d2ff7b332d..830a6412f0 100644
--- a/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
+++ b/OpenSim/Region/CoreModules/World/Wind/Plugins/SimpleRandomWind.cs
@@ -40,7 +40,6 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins
{
private Vector2[] m_windSpeeds = new Vector2[16 * 16];
private float m_strength = 1.0f;
- private Random m_rndnums = new Random(Environment.TickCount);
#region IPlugin Members
@@ -92,8 +91,8 @@ namespace OpenSim.Region.CoreModules.World.Wind.Plugins
{
for (int x = 0; x < 16; x++)
{
- m_windSpeeds[y * 16 + x].X = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
- m_windSpeeds[y * 16 + x].Y = (float)(m_rndnums.NextDouble() * 2d - 1d); // -1 to 1
+ m_windSpeeds[y * 16 + x].X = (float)(Random.Shared.NextDouble() * 2d - 1d); // -1 to 1
+ m_windSpeeds[y * 16 + x].Y = (float)(Random.Shared.NextDouble() * 2d - 1d); // -1 to 1
m_windSpeeds[y * 16 + x].X *= m_strength;
m_windSpeeds[y * 16 + x].Y *= m_strength;
}
diff --git a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs
index f76eac1afc..45dd671720 100755
--- a/OpenSim/Region/CoreModules/World/Wind/WindModule.cs
+++ b/OpenSim/Region/CoreModules/World/Wind/WindModule.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Region.CoreModules
private uint m_frame = 0;
private int m_dataVersion = 0;
private int m_frameUpdateRate = 150;
- //private Random m_rndnums = new Random(Environment.TickCount);
+
private Scene m_scene = null;
private bool m_ready = false;
private bool m_inUpdate = false;
diff --git a/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs b/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs
index 748d14de2e..0fa37dc912 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs
@@ -167,19 +167,19 @@ namespace OpenSim.Region.Framework.Scenes.Animation
Joints[0].Priority = 7;
Joints[0].positionkeys = new binBVHJointKey[1];
Joints[0].rotationkeys = new binBVHJointKey[1];
- Random rnd = new Random();
+
Joints[0].rotationkeys[0] = new binBVHJointKey();
Joints[0].rotationkeys[0].time = (0f);
- Joints[0].rotationkeys[0].key_element.X = ((float)rnd.NextDouble() * 2 - 1);
- Joints[0].rotationkeys[0].key_element.Y = ((float)rnd.NextDouble() * 2 - 1);
- Joints[0].rotationkeys[0].key_element.Z = ((float)rnd.NextDouble() * 2 - 1);
+ Joints[0].rotationkeys[0].key_element.X = ((float)Random.Shared.NextDouble() * 2 - 1);
+ Joints[0].rotationkeys[0].key_element.Y = ((float)Random.Shared.NextDouble() * 2 - 1);
+ Joints[0].rotationkeys[0].key_element.Z = ((float)Random.Shared.NextDouble() * 2 - 1);
Joints[0].positionkeys[0] = new binBVHJointKey();
Joints[0].positionkeys[0].time = (0f);
- Joints[0].positionkeys[0].key_element.X = ((float)rnd.NextDouble() * 2 - 1);
- Joints[0].positionkeys[0].key_element.Y = ((float)rnd.NextDouble() * 2 - 1);
- Joints[0].positionkeys[0].key_element.Z = ((float)rnd.NextDouble() * 2 - 1);
+ Joints[0].positionkeys[0].key_element.X = ((float)Random.Shared.NextDouble() * 2 - 1);
+ Joints[0].positionkeys[0].key_element.Y = ((float)Random.Shared.NextDouble() * 2 - 1);
+ Joints[0].positionkeys[0].key_element.Z = ((float)Random.Shared.NextDouble() * 2 - 1);
}
diff --git a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
index 964acd102f..a30c53ca83 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/ScenePresenceAnimator.cs
@@ -790,14 +790,13 @@ namespace OpenSim.Region.Framework.Scenes.Animation
anim.Joints[j].Priority = 7;
anim.Joints[j].positionkeys = new binBVHJointKey[rnditerations];
anim.Joints[j].rotationkeys = new binBVHJointKey[rnditerations];
- Random rnd = new Random();
for (int i = 0; i < rnditerations; i++)
{
anim.Joints[j].rotationkeys[i] = new binBVHJointKey();
anim.Joints[j].rotationkeys[i].time = (i * .10f);
- anim.Joints[j].rotationkeys[i].key_element.X = ((float)rnd.NextDouble() * 2 - 1);
- anim.Joints[j].rotationkeys[i].key_element.Y = ((float)rnd.NextDouble() * 2 - 1);
- anim.Joints[j].rotationkeys[i].key_element.Z = ((float)rnd.NextDouble() * 2 - 1);
+ anim.Joints[j].rotationkeys[i].key_element.X = ((float)Random.Shared.NextDouble() * 2 - 1);
+ anim.Joints[j].rotationkeys[i].key_element.Y = ((float)Random.Shared.NextDouble() * 2 - 1);
+ anim.Joints[j].rotationkeys[i].key_element.Z = ((float)Random.Shared.NextDouble() * 2 - 1);
anim.Joints[j].positionkeys[i] = new binBVHJointKey();
anim.Joints[j].positionkeys[i].time = (i * .10f);
anim.Joints[j].positionkeys[i].key_element.X = 0;
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index d52f24922b..bcbba2b9ce 100755
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -146,9 +146,8 @@ namespace OpenSim.Region.Framework.Scenes
EntityBase[] entities = Entities.GetEntities();
foreach (EntityBase ent in entities)
{
- if (ent is SceneObjectGroup)
+ if (ent is SceneObjectGroup sog)
{
- SceneObjectGroup sog = ent as SceneObjectGroup;
sog.CreateScriptInstances(0, false, DefaultScriptEngine, 0);
sog.ResumeScripts();
}
@@ -797,10 +796,8 @@ namespace OpenSim.Region.Framework.Scenes
Normalized55FPS = true;
SeeIntoRegion = true;
- Random random = new();
-
- m_lastAllocatedLocalId = (int)(random.NextDouble() * (uint.MaxValue / 4));
- m_lastAllocatedIntId = (int)(random.NextDouble() * (int.MaxValue / 4));
+ m_lastAllocatedLocalId = (int)(Random.Shared.NextDouble() * (uint.MaxValue / 4));
+ m_lastAllocatedIntId = (int)(Random.Shared.NextDouble() * (int.MaxValue / 4));
m_authenticateHandler = authen;
m_sceneGridService = new SceneCommunicationService();
m_SimulationDataService = simDataService;
@@ -6079,9 +6076,9 @@ Environment.Exit(1);
return true;
// Permissions.IsAdministrator is the same as IsGod for now
-// bool isAdmin = Permissions.IsAdministrator(agentID);
-// if(isAdmin)
-// return true;
+ //bool isAdmin = Permissions.IsAdministrator(agentID);
+ //if(isAdmin)
+ // return true;
// also honor estate managers access rights
bool isManager = Permissions.IsEstateManager(agentID);
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index b819023e33..9889738399 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -106,7 +106,7 @@ namespace OpenSim.Region.Framework.Scenes
else
{
if(EnvironmentVersion <= 0)
- EnvironmentVersion = 0x7000000 | Util.RandomClass.Next();
+ EnvironmentVersion = 0x7000000 | Random.Shared.Next();
else
++EnvironmentVersion;
m_environment.version = EnvironmentVersion;
diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
index eca00a0499..6ab9d43e95 100755
--- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
+++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs
@@ -661,7 +661,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
public uint CircuitCode
{
- get { return (uint)Util.RandomClass.Next(0,int.MaxValue); }
+ get { return (uint)Random.Shared.Next(0,int.MaxValue); }
}
public IPEndPoint RemoteEndPoint
diff --git a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs
index d60641c729..a3ac3a3402 100644
--- a/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs
+++ b/OpenSim/Region/OptionalModules/Avatar/Chat/IRCConnector.cs
@@ -232,7 +232,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
// Generate an initial nickname
if (m_randomizeNick)
- m_nick = m_baseNick + Util.RandomClass.Next(1, 99);
+ m_nick = m_baseNick + Random.Shared.Next(1, 99);
else
m_nick = m_baseNick;
@@ -673,7 +673,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Chat
break;
case "433": // Nickname in use
// Gen a new name
- m_nick = m_baseNick + Util.RandomClass.Next(1, 99);
+ m_nick = m_baseNick + Random.Shared.Next(1, 99);
m_log.ErrorFormat("[IRC-Connector-{0}]: [{1}] IRC SERVER reports NicknameInUse, trying {2}", idn, cmd, m_nick);
// Retry
m_writer.WriteLine(String.Format("NICK {0}", m_nick));
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 59e6c4352d..d57fbf8be6 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -190,7 +190,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
}
agentID = npcAvatar.AgentId;
- uint circuit = (uint)Util.RandomClass.Next(0, int.MaxValue);
+ uint circuit = (uint)Random.Shared.Next(0, int.MaxValue);
npcAvatar.CircuitCode = circuit;
//m_log.DebugFormat(
diff --git a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs
index 9c7a938a0b..2d0c7d8fae 100644
--- a/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs
+++ b/OpenSim/Region/OptionalModules/World/TreePopulator/TreePopulatorModule.cs
@@ -698,7 +698,7 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
SceneObjectPart s_tree = sog.RootPart;
if (s_tree.Scale.Z < maxscale)
{
- ratescale = (float)Util.RandomClass.NextDouble();
+ ratescale = (float)Random.Shared.NextDouble();
if(ratescale < 0.2f)
ratescale = 0.2f;
s_tree.Scale += copse.m_rate * ratescale;
@@ -727,7 +727,7 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
bool low = copse.m_trees.Count < (int)(copse.m_tree_quantity * 0.8f);
- if (!low && Util.RandomClass.NextDouble() < 0.75)
+ if (!low && Random.Shared.NextDouble() < 0.75)
return;
int maxbirths = (int)(copse.m_tree_quantity) - copse.m_trees.Count;
@@ -746,7 +746,7 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
while(--maxbirths > 0)
{
if(current.Length > 1)
- i = Util.RandomClass.Next(current.Length -1);
+ i = Random.Shared.Next(current.Length -1);
UUID tree = current[i];
SceneObjectGroup sog = m_scene.GetSceneObjectGroup(tree);
@@ -772,7 +772,7 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
if (copse.m_frozen)
continue;
- if (Util.RandomClass.NextDouble() < 0.25)
+ if (Random.Shared.NextDouble() < 0.25)
return;
int maxbdeaths = copse.m_trees.Count - (int)(copse.m_tree_quantity * .98f) ;
@@ -787,7 +787,7 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
{
int next = 0;
if (copse.m_trees.Count > 1)
- next = Util.RandomClass.Next(copse.m_trees.Count - 1);
+ next = Random.Shared.Next(copse.m_trees.Count - 1);
UUID tree = copse.m_trees[next];
SceneObjectGroup sog = m_scene.GetSceneObjectGroup(tree);
if (sog != null && !sog.IsDeleted)
@@ -796,11 +796,11 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
{
odds = sog.RootPart.Scale.Z * scale;
odds = odds * odds * odds;
- odds *= (float)Util.RandomClass.NextDouble();
+ odds *= (float)Random.Shared.NextDouble();
}
else
{
- odds = (float)Util.RandomClass.NextDouble();
+ odds = (float)Random.Shared.NextDouble();
odds = odds * odds * odds;
}
@@ -824,15 +824,15 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
private void SpawnChild(Copse copse, SceneObjectPart s_tree, bool low)
{
Vector3 position = new Vector3();
-
+
float randX = copse.m_maximum_scale.X * 1.25f;
float randY = copse.m_maximum_scale.Y * 1.25f;
-
- float r = (float)Util.RandomClass.NextDouble();
+
+ float r = (float)Random.Shared.NextDouble();
randX *= 2.0f * r - 1.0f;
position.X = s_tree.AbsolutePosition.X + (float)randX;
-
- r = (float)Util.RandomClass.NextDouble();
+
+ r = (float)Random.Shared.NextDouble();
randY *= 2.0f * r - 1.0f;
position.Y = s_tree.AbsolutePosition.Y + (float)randY;
@@ -865,9 +865,9 @@ namespace OpenSim.Region.OptionalModules.World.TreePopulator
try
{
float t;
- float r = (float)Util.RandomClass.NextDouble();
- r *= (float)Util.RandomClass.NextDouble();
- r *= (float)Util.RandomClass.NextDouble();
+ float r = (float)Random.Shared.NextDouble();
+ r *= (float)Random.Shared.NextDouble();
+ r *= (float)Random.Shared.NextDouble();
t = copse.m_maximum_scale.X / copse.m_initial_scale.X;
if(t < 1.0)
diff --git a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
index 02519197e0..12a5fc37d3 100644
--- a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
+++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
@@ -256,8 +256,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
///
private int latertickcount;
- private Random fluidRandomizer = new Random(Environment.TickCount);
-
private uint m_regionWidth = Constants.RegionSize;
private uint m_regionHeight = Constants.RegionSize;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 3df2569b62..6e962c5856 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -913,10 +913,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Float llFrand(double mag)
{
- lock (Util.RandomClass)
- {
- return Util.RandomClass.NextDouble() * mag;
- }
+ return Random.Shared.NextDouble() * mag;
}
public LSL_Integer llFloor(double f)
@@ -5985,12 +5982,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_List llListRandomize(LSL_List src, int stride)
{
LSL_List result;
- Random rand = new Random();
int chunkk;
int[] chunks;
-
if (stride <= 0)
{
stride = 1;
@@ -6015,7 +6010,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
for (int i = chunkk - 1; i > 0; i--)
{
// Elect an unrandomized chunk to swap
- int index = rand.Next(i + 1);
+ int index = Random.Shared.Next(i + 1);
// and swap position with first unrandomized chunk
int tmp = chunks[i];
diff --git a/OpenSim/Services/GridService/HypergridLinker.cs b/OpenSim/Services/GridService/HypergridLinker.cs
index 458d5ecaf6..b2962054c0 100644
--- a/OpenSim/Services/GridService/HypergridLinker.cs
+++ b/OpenSim/Services/GridService/HypergridLinker.cs
@@ -142,7 +142,7 @@ namespace OpenSim.Services.GridService
public GridRegion LinkRegion(UUID scopeID, string regionDescriptor)
{
string reason = string.Empty;
- uint xloc = Util.RegionToWorldLoc((uint)random.Next(0, Int16.MaxValue));
+ uint xloc = Util.RegionToWorldLoc((uint)Random.Shared.Next(0, Int16.MaxValue));
return TryLinkRegionToCoords(scopeID, regionDescriptor, (int)xloc, 0, out reason);
}
@@ -157,7 +157,7 @@ namespace OpenSim.Services.GridService
return null;
}
- int xloc = random.Next(0, short.MaxValue) << 8;
+ int xloc = Random.Shared.Next(0, short.MaxValue) << 8;
if(TryCreateLinkImpl(scopeID, xloc, 0, rurl, UUID.Zero, out GridRegion regInfo))
return regInfo;
return null;
@@ -243,8 +243,6 @@ namespace OpenSim.Services.GridService
return true;
}
- private static Random random = new Random();
-
// From the command line link-region (obsolete) and the map
private GridRegion TryLinkRegionToCoords(UUID scopeID, string mapName, int xloc, int yloc, out string reason)
{
diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs
index 9c4ce1a01a..d35ad782d5 100755
--- a/OpenSim/Services/LLLoginService/LLLoginService.cs
+++ b/OpenSim/Services/LLLoginService/LLLoginService.cs
@@ -888,7 +888,7 @@ namespace OpenSim.Services.LLLoginService
if(simConnector == null)
return null;
- circuitCode = (uint)Util.RandomClass.Next();
+ circuitCode = (uint)Random.Shared.Next();
aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position,
clientIP.Address.ToString(), viewer, channel, mac, id0);
@@ -925,7 +925,7 @@ namespace OpenSim.Services.LLLoginService
gatekeeper.HttpPort = (uint)port;
gatekeeper.ServerURI = m_GatekeeperURL;
}
- circuitCode = (uint)Util.RandomClass.Next(); ;
+ circuitCode = (uint)Random.Shared.Next();
aCircuit = MakeAgent(destination, account, avatar, session, secureSession, circuitCode, position,
clientIP.Address.ToString(), viewer, channel, mac, id0);