From 9935219a1c4c2978b06fa1d00d02f8bde196ee70 Mon Sep 17 00:00:00 2001 From: Rye Mutt <rye@alchemyviewer.org> Date: Mon, 5 Oct 2020 19:09:56 -0400 Subject: [PATCH] Replace C rand with ll_rand in most cases --- indra/llaudio/llwindgen.h | 2 +- indra/llcommon/tests/commonmisc_test.cpp | 7 ++++--- indra/llcommon/tests/llsdserialize_test.cpp | 3 ++- indra/llinventory/tests/inventorymisc_test.cpp | 13 +++++++------ indra/llxml/llxmlnode.cpp | 5 +++-- indra/newview/llagent.cpp | 2 +- indra/newview/llappviewer.cpp | 4 ++-- indra/newview/llfloatermodelpreview.cpp | 2 +- indra/newview/llspatialpartition.cpp | 2 +- indra/newview/lltoolplacer.cpp | 4 ++-- indra/test/io.cpp | 5 +++-- indra/test/llpipeutil.cpp | 2 +- 12 files changed, 28 insertions(+), 23 deletions(-) diff --git a/indra/llaudio/llwindgen.h b/indra/llaudio/llwindgen.h index e60e1c8ee3f..78c7e6ecccf 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 4b3e07fa75a..f897830e142 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 1be5ac90c9d..c699ccd903e 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 7b15552f246..054644b129b 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 6f31c78dd7b..3e0951ef32c 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 ddd04d02203..d0bfa365ad2 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 8b525b7b019..2cb9d9bc459 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 4658b7a58a8..ef4a2bec879 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 fd303cc945f..c6e2d9af77a 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 aabccb28926..f9c91d7d820 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 40243a8ad6e..7aadf5a85b9 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 bb706b58d5f..7a70c1281d0 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; -- GitLab