diff --git a/indra/llaudio/llwindgen.h b/indra/llaudio/llwindgen.h
index e60e1c8ee3ff685b69e5692e521d875ddbabd355..78c7e6ecccfd2f70c82efbef9cb0cf900b57f05a 100644
--- a/indra/llaudio/llwindgen.h
+++ b/indra/llaudio/llwindgen.h
@@ -166,7 +166,7 @@ class LLWindGen
 	F32 mLastSample;
 };
 
-template<class T> inline const F32 LLWindGen<T>::getNextSample() { return (F32)rand() * (1.0f / (F32)(RAND_MAX / (U16_MAX / 8))) + (F32)(S16_MIN / 8); }
+template<class T> inline const F32 LLWindGen<T>::getNextSample() { return (F32)ll_rand() * (1.0f / (F32)(RAND_MAX / (U16_MAX / 8))) + (F32)(S16_MIN / 8); }
 template<> inline const F32 LLWindGen<F32>::getNextSample() { return ll_frand()-.5f; }
 template<class T> inline const F32 LLWindGen<T>::getClampedSample(bool clamp, F32 sample) { return clamp ? (F32)llclamp((S32)sample,(S32)S16_MIN,(S32)S16_MAX) : sample; }
 template<> inline const F32 LLWindGen<F32>::getClampedSample(bool clamp, F32 sample) { return sample; }
diff --git a/indra/llcommon/tests/commonmisc_test.cpp b/indra/llcommon/tests/commonmisc_test.cpp
index 4b3e07fa75a40d13747d58fe3c459de3a8d1f16e..f897830e142b370ab8aa429b50ceae8584440b67 100644
--- a/indra/llcommon/tests/commonmisc_test.cpp
+++ b/indra/llcommon/tests/commonmisc_test.cpp
@@ -43,6 +43,7 @@
 #include "../llsdserialize.h"
 #include "../u64.h"
 #include "../llhash.h"
+#include "../llrand.h"
 
 #include "../test/lltut.h"
 
@@ -118,7 +119,7 @@ namespace tut
 			typedef std::vector<U8> buf_t;
 			buf_t source;
 			srand(i);		/* Flawfinder: ignore */
-			S32 size = rand() % 1000 + 10;
+			S32 size = ll_rand() % 1000 + 10;
 			std::generate_n(
 				std::back_insert_iterator<buf_t>(source),
 				size,
@@ -169,7 +170,7 @@ namespace tut
 			typedef std::vector<U8> buf_t;
 			buf_t source;
 			srand(666 + i);		/* Flawfinder: ignore */
-			S32 size = rand() % 1000 + 10;
+			S32 size = ll_rand() % 1000 + 10;
 			std::generate_n(
 				std::back_insert_iterator<buf_t>(source),
 				size,
@@ -325,7 +326,7 @@ namespace tut
 			// gen up a starting point
 			std::string expected;
 			srand(1337 + i);		/* Flawfinder: ignore */
-			S32 size = rand() % 30 + 5;
+			S32 size = ll_rand() % 30 + 5;
 			std::generate_n(
 				std::back_insert_iterator<std::string>(expected),
 				size,
diff --git a/indra/llcommon/tests/llsdserialize_test.cpp b/indra/llcommon/tests/llsdserialize_test.cpp
index 1be5ac90c9d0c76c9ea08c739b018f512e06a12d..c699ccd903ebab6ca141e12a6f73826c8a22cbf6 100644
--- a/indra/llcommon/tests/llsdserialize_test.cpp
+++ b/indra/llcommon/tests/llsdserialize_test.cpp
@@ -59,6 +59,7 @@ using namespace boost::phoenix;
 #include "../test/lltut.h"
 #include "../test/namedtempfile.h"
 #include "stringize.h"
+#include "llrand.h"
 
 std::vector<U8> string_to_vector(const std::string& str)
 {
@@ -1660,7 +1661,7 @@ namespace tut
 		for(int ii = 0; ii < 100; ++ii)
 		{
 			srand(ii);		/* Flawfinder: ignore */
-			S32 size = rand() % 100 + 10;
+			S32 size = ll_rand() % 100 + 10;
 			std::generate_n(
 				std::back_insert_iterator<buf_t>(val),
 				size,
diff --git a/indra/llinventory/tests/inventorymisc_test.cpp b/indra/llinventory/tests/inventorymisc_test.cpp
index 7b15552f24646d5be386f93471ffea8c829be067..054644b129b72d4ef79873078e25b1e0196ff28f 100644
--- a/indra/llinventory/tests/inventorymisc_test.cpp
+++ b/indra/llinventory/tests/inventorymisc_test.cpp
@@ -28,6 +28,7 @@
 
 #include "linden_common.h"
 #include "llsd.h"
+#include "llrand.h"
 
 #include "../llinventory.h"
 
@@ -58,9 +59,9 @@ LLPointer<LLInventoryItem> create_random_inventory_item()
 	perm.initMasks(PERM_ALL, PERM_ALL, PERM_COPY, PERM_COPY, PERM_MODIFY | PERM_COPY);
 	LLUUID asset_id;
 	asset_id.generate();
-	S32 price = rand();
+	S32 price = ll_rand();
 	LLSaleInfo sale_info(LLSaleInfo::FS_COPY, price);
-	U32 flags = rand();
+	U32 flags = ll_rand();
 	S32 creation = time(NULL);
 
 	LLPointer<LLInventoryItem> item = new LLInventoryItem(
@@ -190,11 +191,11 @@ namespace tut
 		std::string new_desc = "SecondLife Testing";
 		src->setDescription(new_desc);
 		
-		S32 new_price = rand();
+		S32 new_price = ll_rand();
 		LLSaleInfo new_sale_info(LLSaleInfo::FS_COPY, new_price);
 		src->setSaleInfo(new_sale_info);
 
-		U32 new_flags = rand();
+		U32 new_flags = ll_rand();
 		S32 new_creation = time(NULL);
 
 		LLPermissions new_perm;
@@ -261,11 +262,11 @@ namespace tut
 		std::string new_desc = "SecondLife Testing";
 		src->setDescription(new_desc);
 		
-		S32 new_price = rand();
+		S32 new_price = ll_rand();
 		LLSaleInfo new_sale_info(LLSaleInfo::FS_COPY, new_price);
 		src->setSaleInfo(new_sale_info);
 
-		U32 new_flags = rand();
+		U32 new_flags = ll_rand();
 		S32 new_creation = time(NULL);
 
 		LLPermissions new_perm;
diff --git a/indra/llxml/llxmlnode.cpp b/indra/llxml/llxmlnode.cpp
index 6f31c78dd7bf1cc6cf9572db6dfb5f4e54b83afb..3e0951ef32c3b0ea9c64ddfac2c3b355aca388ec 100644
--- a/indra/llxml/llxmlnode.cpp
+++ b/indra/llxml/llxmlnode.cpp
@@ -43,6 +43,8 @@
 #include "lluuid.h"
 #include "lldir.h"
 
+#include "llrand.h"
+
 // static
 BOOL LLXMLNode::sStripEscapedStrings = TRUE;
 BOOL LLXMLNode::sStripWhitespaceValues = FALSE;
@@ -2715,8 +2717,7 @@ U32 LLXMLNode::getChildCount() const
 
 U32 get_rand(U32 max_value)
 {
-	U32 random_num = rand() + ((U32)rand() << 16);
-	return (random_num % max_value);
+	return ll_rand(max_value);
 }
 
 LLXMLNode *get_rand_node(LLXMLNode *node)
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index ddd04d022037f2d42eb3f5b175f67ccaf0074a86..d0bfa365ad2f0220b217f8256b0a97b31176b11d 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -2571,7 +2571,7 @@ void LLAgent::onAnimStop(const LLUUID& id)
 		setControlFlags(AGENT_CONTROL_FINISH_ANIM);
 
 		// now trigger dusting self off animation
-		if (isAgentAvatarValid() && !gAgentAvatarp->mBelowWater && rand() % 3 == 0)
+		if (isAgentAvatarValid() && !gAgentAvatarp->mBelowWater && ll_rand() % 3 == 0)
 			sendAnimationRequest( ANIM_AGENT_BRUSH, ANIM_REQUEST_START );
 	}
 	else if (id == ANIM_AGENT_PRE_JUMP || id == ANIM_AGENT_LAND || id == ANIM_AGENT_MEDIUM_LAND)
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 8b525b7b019bcd6335997dbcf1f5ae962f81ba9a..2cb9d9bc459f49c01c9c9d9ba5012510f4c55a45 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1535,7 +1535,7 @@ bool LLAppViewer::doFrame()
 
 			if (mRandomizeFramerate)
 			{
-				ms_sleep(rand() % 200);
+				ms_sleep(ll_rand() % 200);
 			}
 
 			if (mPeriodicSlowFrame
@@ -4301,7 +4301,7 @@ bool LLAppViewer::initCache()
 	{
 		do
 		{
-			new_salt = rand();
+			new_salt = ll_rand(S32_MAX);
 		} while(new_salt == old_salt);
 	}
 
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index 4658b7a58a842e2e897d47f0664fcb2159fb18e9..ef4a2bec879f0e285ccc284b2897565bf3269c4f 100644
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -3986,7 +3986,7 @@ BOOL LLModelPreview::render()
 
 											if (i+1 >= hull_colors.size())
 											{
-												hull_colors.push_back(LLColor4U(rand()%128+127, rand()%128+127, rand()%128+127, 128));
+												hull_colors.push_back(LLColor4U(ll_rand()%128+127, ll_rand()%128+127, ll_rand()%128+127, 128));
 											}
 
 											gGL.diffuseColor4ubv(hull_colors[i].mV);
diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index fd303cc945f25d8516d6ae511d1439c1c23043b9..c6e2d9af77a7a93fc3f0bd8ebc7a54157fda9d32 100644
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -4012,7 +4012,7 @@ LLDrawInfo::LLDrawInfo(U16 start, U16 end, U32 count, U32 offset,
 {
 	mVertexBuffer->validateRange(mStart, mEnd, mCount, mOffset);
 	
-	mDebugColor = ((U32)rand() << 16) + rand();
+	mDebugColor = ((U32)ll_rand() << 16) + ll_rand();
 }
 
 LLDrawInfo::~LLDrawInfo()	
diff --git a/indra/newview/lltoolplacer.cpp b/indra/newview/lltoolplacer.cpp
index aabccb289266f3c6e2491a8ebff0bdca13807674..f9c91d7d820fafc57703b4c7a1b382941e517f0d 100644
--- a/indra/newview/lltoolplacer.cpp
+++ b/indra/newview/lltoolplacer.cpp
@@ -213,13 +213,13 @@ BOOL LLToolPlacer::addObject( LLPCode pcode, S32 x, S32 y, U8 use_physics )
 	case LL_PCODE_LEGACY_GRASS:
 		//  Randomize size of grass patch 
 		scale.setVec(10.f + ll_frand(20.f), 10.f + ll_frand(20.f),  1.f + ll_frand(2.f));
-		state = rand() % LLVOGrass::sMaxGrassSpecies;
+		state = ll_rand() % LLVOGrass::sMaxGrassSpecies;
 		break;
 
 
 	case LL_PCODE_LEGACY_TREE:
 	case LL_PCODE_TREE_NEW:
-		state = rand() % LLVOTree::sMaxTreeSpecies;
+		state = ll_rand() % LLVOTree::sMaxTreeSpecies;
 		break;
 
 	case LL_PCODE_SPHERE:
diff --git a/indra/test/io.cpp b/indra/test/io.cpp
index 40243a8ad6ef6505f9f2988db9b2c8dea9d3c6bc..7aadf5a85b93b931bf804ebba638a916e1fb0a2f 100644
--- a/indra/test/io.cpp
+++ b/indra/test/io.cpp
@@ -45,6 +45,7 @@
 #include "llcommon.h"
 #include "lluuid.h"
 #include "llinstantmessage.h"
+#include "llrand.h"
 
 namespace tut
 {
@@ -604,7 +605,7 @@ namespace tut
 			}
 			need_comma = true;
 			srand(69 + i);	/* Flawfinder: ignore */
-			S32 size = rand() % 1000 + 1000;
+			S32 size = ll_rand() % 1000 + 1000;
 			std::generate_n(
 				std::back_insert_iterator<buf_t>(source),
 				size,
@@ -670,7 +671,7 @@ namespace tut
 			ostr << "'" << i << "':";
 			total_size += 7;
 			srand(69 + i);		/* Flawfinder: ignore */
-			S32 size = rand() % 1000 + 1000;
+			S32 size = ll_rand() % 1000 + 1000;
 			std::generate_n(
 				std::back_insert_iterator<buf_t>(source),
 				size,
diff --git a/indra/test/llpipeutil.cpp b/indra/test/llpipeutil.cpp
index bb706b58d5f56b79c7fb877d9f495d9e375b028a..7a70c1281d025ffa44e7f09c4aa08e143f05b75d 100644
--- a/indra/test/llpipeutil.cpp
+++ b/indra/test/llpipeutil.cpp
@@ -119,7 +119,7 @@ struct random_ascii_generator
 	random_ascii_generator() {}
 	U8 operator()()
 	{
-		int rv = rand();
+		int rv = ll_rand();
 		rv %= (127 - 32);
 		rv += 32;
 		return rv;