REORG: tools: promote the debug PRNG to more general use as a statistical one

We frequently need to access a simple and fast PRNG for statistical
purposes. The debug_prng() function did exactly this using a xorshift
generator but its use was limited to debug only. Let's move this to
tools.h and tools.c to make it accessible everywhere. Since it needs to
be fast, its state is thread-local. An initialization function starts a
different initial value for each thread for better distribution.
diff --git a/src/tools.c b/src/tools.c
index 1c43354..d3ee426 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -78,6 +78,12 @@
 THREAD_LOCAL char quoted_str[NB_QSTR][QSTR_SIZE + 1];
 THREAD_LOCAL int quoted_idx = 0;
 
+/* thread-local PRNG state. It's modified to start from a different sequence
+ * on all threads upon startup. It must not be used or anything beyond getting
+ * statistical values as it's 100% predictable.
+ */
+THREAD_LOCAL unsigned int statistical_prng_state = 2463534242U;
+
 /*
  * unsigned long long ASCII representation
  *
@@ -5362,6 +5368,16 @@
 	*out++ = 0;
 	return pos - shift;
 }
+
+static int init_tools_per_thread()
+{
+	/* Let's make each thread start from a different position */
+	statistical_prng_state += tid * MAX_THREADS;
+	if (!statistical_prng_state)
+		statistical_prng_state++;
+	return 1;
+}
+REGISTER_PER_THREAD_INIT(init_tools_per_thread);
 
 /*
  * Local variables: