aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/lluuid.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/llmath/lluuid.cpp75
1 files changed, 62 insertions, 13 deletions
diff --git a/linden/indra/llmath/lluuid.cpp b/linden/indra/llmath/lluuid.cpp
index 216dac9..3fb31a6 100644
--- a/linden/indra/llmath/lluuid.cpp
+++ b/linden/indra/llmath/lluuid.cpp
@@ -110,6 +110,40 @@ unsigned int decode( char const * fiveChars ) throw( bad_input_data )
110} 110}
111*/ 111*/
112 112
113#define LL_USE_JANKY_RANDOM_NUMBER_GENERATOR 0
114#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
115/**
116 * @brief a global for
117 */
118static U64 sJankyRandomSeed(LLUUID::getRandomSeed());
119
120/**
121 * @brief generate a random U32.
122 */
123U32 janky_fast_random_bytes()
124{
125 sJankyRandomSeed = U64L(1664525) * sJankyRandomSeed + U64L(1013904223);
126 return (U32)sJankyRandomSeed;
127}
128
129/**
130 * @brief generate a random U32 from [0, val)
131 */
132U32 janky_fast_random_byes_range(U32 val)
133{
134 sJankyRandomSeed = U64L(1664525) * sJankyRandomSeed + U64L(1013904223);
135 return (U32)(sJankyRandomSeed) % val;
136}
137
138/**
139 * @brief generate a random U32 from [0, val)
140 */
141U32 janky_fast_random_seeded_bytes(U32 seed, U32 val)
142{
143 seed = U64L(1664525) * (U64)(seed) + U64L(1013904223);
144 return (U32)(seed) % val;
145}
146#endif
113 147
114// Common to all UUID implementations 148// Common to all UUID implementations
115void LLUUID::toString(char *out) const 149void LLUUID::toString(char *out) const
@@ -395,8 +429,16 @@ static void get_random_bytes(void *buf, int nbytes)
395 int i; 429 int i;
396 char *cp = (char *) buf; 430 char *cp = (char *) buf;
397 431
432 // *NOTE: If we are not using the janky generator ll_rand()
433 // generates at least 3 good bytes of data since it is 0 to
434 // RAND_MAX. This could be made more efficient by copying all the
435 // bytes.
398 for (i=0; i < nbytes; i++) 436 for (i=0; i < nbytes; i++)
399 *cp++ = gLindenLabRandomNumber.llrand() & 0xFF; 437#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
438 *cp++ = janky_fast_random_bytes() & 0xFF;
439#else
440 *cp++ = ll_rand() & 0xFF;
441#endif
400 return; 442 return;
401} 443}
402 444
@@ -738,18 +780,18 @@ void LLUUID::getCurrentTime(uuid_time_t *timestamp)
738 780
739void LLUUID::generate() 781void LLUUID::generate()
740{ 782{
741 // Create a UUID. 783 // Create a UUID.
742 784 uuid_time_t timestamp;
743
744 uuid_time_t timestamp;
745 785
746 static unsigned char node_id[6]; 786 static unsigned char node_id[6];
747 static int has_init = 0; 787 static int has_init = 0;
748 788
749 // Create a UUID. 789 // Create a UUID.
750 static uuid_time_t time_last = {0,0}; 790 static uuid_time_t time_last = {0,0};
751 static U16 clock_seq = 0; 791 static U16 clock_seq = 0;
752 static LLRand random_generator(0); // dummy seed. reset it below 792#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
793 static U32 seed = 0L; // dummy seed. reset it below
794#endif
753 if (!has_init) 795 if (!has_init)
754 { 796 {
755 if (getNodeID(node_id) <= 0) 797 if (getNodeID(node_id) <= 0)
@@ -764,8 +806,15 @@ void LLUUID::generate()
764 } 806 }
765 807
766 getCurrentTime(&time_last); 808 getCurrentTime(&time_last);
767 random_generator.seed(time_last.low); 809#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
768 clock_seq = (U16) random_generator.llrand(65536); 810 seed = time_last.low;
811#endif
812
813#if LL_USE_JANKY_RANDOM_NUMBER_GENERATOR
814 clock_seq = (U16)janky_fast_random_seeded_bytes(seed, 65536);
815#else
816 clock_seq = (U16)ll_rand(65536);
817#endif
769 has_init = 1; 818 has_init = 1;
770 } 819 }
771 820